#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 {
  char *pw_name;
};

/* Variables and functions */
int errno;
int /*<<< orphan*/ geteuid();
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  struct passwd *user = getpwuid(geteuid());
  if (user == NULL) {
    perror("whoami");
    return errno;
  }
  write(1, user->pw_name, strlen(user->pw_name));
  write(1, "\n", 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <main+0x49>
lea    0xe7d(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11da <main+0x8a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    $0x1,%edx
lea    0xe3b(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     11a1 <main+0x51>
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe7e(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe58(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%ebp
jmp    1198 <main+0x48>

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [7 x i8] c"whoami\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.passwd*
store i32 0, i32* %1
%3 = call i32 (...) @geteuid()
%4 = call %struct.passwd* @getpwuid(i32 %3)
store %struct.passwd* %4, %struct.passwd** %2
%5 = load %struct.passwd*, %struct.passwd** %2
%6 = icmp eq %struct.passwd* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @errno
store i32 %9, i32* %1
br label %20
10: ; preds = %0
%11 = load %struct.passwd*, %struct.passwd** %2
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = load %struct.passwd*, %struct.passwd** %2
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = call i32 @strlen(i8* %16)
%18 = call i32 @write(i32 1, i8* %13, i32 %17)
%19 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32 0, i32* %1
br label %20
20: ; preds = %10, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [7 x i8] c"whoami\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%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 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @errno
br label %13
7: ; preds = %0
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = tail call i32 @write(i32 1, i8* %9, i32 %10)
%12 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %13
13: ; preds = %7, %4
%14 = phi i32 [ %6, %4 ], [ 0, %7 ]
ret i32 %14
}