#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;
};
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ err_exit(char *);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int geteuid();
int getopt(int, char **, char *);
struct passwd *getpwuid(int);
int /*<<< orphan*/ printUsage();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  uid_t uid;
  int32_t option;
  struct passwd *pw;
  while ((option = getopt(argc, argv, "h")) != -1) {
    switch (option) {
    case 'h':
      printUsage();
    default:
      err_exit("Try 'whoami -h' for more information\n");
    }
  }
  uid = geteuid();
  if ((pw = getpwuid(uid)) != NULL) {
    fprintf(stdout, "%s\n", pw->pw_name);
  } else {
    fprintf(stderr, "cannot find name for user id %u, errno is %d\n", uid,
            errno);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     11ce <main+0x5e>
mov    -0x18(%rbp),%eax
sub    $0x68,%eax
jne    11bd <main+0x4d>
jmp    11b6 <main+0x46>
mov    $0x0,%al
call   1070 <printUsage@plt>
lea    0xe3e(%rip),%rdi
call   1060 <err_exit@plt>
jmp    1186 <main+0x16>
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1211 <main+0xa1>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1234 <main+0xc4>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    0x2db4(%rip),%rax
mov    (%rax),%ecx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe7d(%rip),%r14
lea    0xe78(%rip),%r15
jmp    119f <main+0x2f>
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <printUsage@plt>
mov    %r15,%rdi
call   1060 <err_exit@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1080 <getopt@plt>
cmp    $0x68,%eax
je     1190 <main+0x20>
cmp    $0xffffffff,%eax
jne    1197 <main+0x27>
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
jne    11ef <main+0x7f>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    0x2dfd(%rip),%rax
mov    (%rax),%ecx
lea    0xe48(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1209 <main+0x99>
mov    0x2dda(%rip),%rcx
mov    (%rcx),%edi
mov    (%rax),%rdx
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [2 x i8] c"h\00"
@.str.1 = [38 x i8] c"Try 'whoami -h' for more information\0A\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.3 = [46 x i8] c"cannot find name for user id %u, errno is %d\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %20, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %7
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load i32, i32* %7
switch i32 %15, label %18 [
i32 104, label %16
]
16: ; preds = %14
%17 = call i32 (...) @printUsage()
br label %18
18: ; preds = %14, %16
%19 = call i32 @err_exit(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18
br label %9
21: ; preds = %9
%22 = call i32 (...) @geteuid()
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call %struct.passwd* @getpwuid(i32 %23)
store %struct.passwd* %24, %struct.passwd** %8
%25 = icmp ne %struct.passwd* %24, null
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i32, i32* @stdout
%28 = load %struct.passwd*, %struct.passwd** %8
%29 = getelementptr inbounds %struct.passwd, %struct.passwd* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %37
32: ; preds = %21
%33 = load i32, i32* @stderr
%34 = load i32, i32* %6
%35 = load i32, i32* @errno
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %35)
br label %37
37: ; preds = %32, %26
%38 = load i32, i32* @EXIT_SUCCESS
%39 = call i32 @exit(i32 %38)
unreachable
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [2 x i8] c"h\00"
@.str.1 = [38 x i8] c"Try 'whoami -h' for more information\0A\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.3 = [46 x i8] c"cannot find name for user id %u, errno is %d\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %7, %2
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
switch i32 %4, label %7 [
i32 -1, label %9
i32 104, label %5
]
5: ; preds = %3
%6 = tail call i32 (...) @printUsage()
br label %7
7: ; preds = %3, %5
%8 = tail call i32 @err_exit(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %3
9: ; preds = %3
%10 = tail call i32 (...) @geteuid()
%11 = tail call %struct.passwd* @getpwuid(i32 %10)
%12 = icmp eq %struct.passwd* %11, null
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = load i32, i32* @stdout
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %22
18: ; preds = %9
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %10, i32 %20)
br label %22
22: ; preds = %18, %13
%23 = load i32, i32* @EXIT_SUCCESS
%24 = tail call i32 @exit(i32 %23)
unreachable
}