#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 */
struct passwd {
  int /*<<< orphan*/ pw_name;
};

/* Variables and functions */
char const *bprintf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ geteuid();
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *, int /*<<< orphan*/);
const char *username(void) {
  struct passwd *pw;
  if (!(pw = getpwuid(geteuid()))) {
    warn("getpwuid '%d':", geteuid());
    return NULL;
  }
  return bprintf("%s", pw->pw_name);
}


x86 assembly (clang, -O0):
<username>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1186 <username+0x46>
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,%esi
lea    0xe8c(%rip),%rdi
call   1030 <warn@plt>
movq   $0x0,-0x8(%rbp)
jmp    119c <username+0x5c>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe7c(%rip),%rdi
call   1050 <bprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<username>:
push   %rax
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1163 <username+0x23>
mov    (%rax),%esi
lea    0xeb2(%rip),%rdi
pop    %rax
jmp    1050 <bprintf@plt>
xor    %eax,%eax
call   1060 <geteuid@plt>
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
call   1030 <warn@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [15 x i8] c"getpwuid '%d':\00"
@.str.1 = [3 x i8] c"%s\00"
define i8* @username() {
%1 = alloca i8*
%2 = alloca %struct.passwd*
%3 = call i32 (...) @geteuid()
%4 = call %struct.passwd* @getpwuid(i32 %3)
store %struct.passwd* %4, %struct.passwd** %2
%5 = icmp ne %struct.passwd* %4, null
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i32 (...) @geteuid()
%8 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7)
store i8* null, i8** %1
br label %14
9: ; preds = %0
%10 = load %struct.passwd*, %struct.passwd** %2
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i8* %13, i8** %1
br label %14
14: ; preds = %9, %6
%15 = load i8*, i8** %1
ret i8* %15
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str = [15 x i8] c"getpwuid '%d':\00"
@.str.1 = [3 x i8] c"%s\00"
define i8* @username() {
%1 = tail call i32 (...) @geteuid()
%2 = tail call %struct.passwd* @getpwuid(i32 %1)
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 (...) @geteuid()
%6 = tail call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %11
7: ; preds = %0
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %7, %4
%12 = phi i8* [ %10, %7 ], [ null, %4 ]
ret i8* %12
}