#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uid_t;
struct passwd {
  char *pw_name;
};

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
struct passwd *getpwuid(int);
int getuid();
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
char *get_username(void) {
  struct passwd *pw;
  uid_t uid;
  uid = getuid();
  pw = getpwuid(uid);
  if (!pw)
    fprintf(stderr, "Error can't get username for UID %d: %s", uid,
            strerror(errno));
  return pw->pw_name;
}


x86 assembly (clang, -O0):
<get_username>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    119e <get_username+0x5e>
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%edx
mov    %rax,%rcx
lea    0xe67(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_username>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <getpwuid@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1188 <get_username+0x48>
mov    0x2e7d(%rip),%rax
mov    (%rax),%r14d
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe85(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    (%rbx),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@stderr = global i32 0
@.str = [40 x i8] c"Error can't get username for UID %d: %s\00"
@errno = global i32 0
define i8* @get_username() {
%1 = alloca %struct.passwd*
%2 = alloca i32
%3 = call i32 (...) @getuid()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = call %struct.passwd* @getpwuid(i32 %4)
store %struct.passwd* %5, %struct.passwd** %1
%6 = load %struct.passwd*, %struct.passwd** %1
%7 = icmp ne %struct.passwd* %6, null
br i1 %7, label %14, label %8
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* %2
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %12)
br label %14
14: ; preds = %8, %0
%15 = load %struct.passwd*, %struct.passwd** %1
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i32 0, i32 0
%17 = load i8*, i8** %16
ret i8* %17
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@stderr = global i32 0
@.str = [40 x i8] c"Error can't get username for UID %d: %s\00"
@errno = global i32 0
define i8* @get_username() {
%1 = tail call i32 (...) @getuid()
%2 = tail call %struct.passwd* @getpwuid(i32 %1)
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %4, label %9
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %7)
br label %9
9: ; preds = %4, %0
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%11 = load i8*, i8** %10
ret i8* %11
}