#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 */

/* Variables and functions */
int /*<<< orphan*/ bu_extra_argument(char *);
scalar_t__ bu_handle_version(int, char **);
char *getlogin();
scalar_t__ has_arg(int, char **, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int main(int argc, char **argv) {
  if (has_arg(argc, argv, "-h") || has_arg(argc, argv, "--help")) {
    puts("Usage: whoami");
    puts("Print effected userid.");
    return 1;
  }
  if (bu_handle_version(argc, argv)) {
    return 0;
  }
  if (argc > 1) {
    bu_extra_argument(argv[0]);
    return 1;
  }
  char *ret = getlogin();
  if (ret == NULL) {
    perror(argv[0]);
    return 1;
  }
  puts(ret);
  return 0;
}


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    0xe7c(%rip),%rdx
call   1040 <has_arg@plt>
cmp    $0x0,%rax
jne    11b0 <main+0x50>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe62(%rip),%rdx
call   1040 <has_arg@plt>
cmp    $0x0,%rax
je     11d4 <main+0x74>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0xf6>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <bu_handle_version@plt>
cmp    $0x0,%rax
je     11f6 <main+0x96>
movl   $0x0,-0x4(%rbp)
jmp    1256 <main+0xf6>
cmpl   $0x1,-0x8(%rbp)
jle    1218 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <bu_extra_argument@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0xf6>
mov    $0x0,%al
call   1050 <getlogin@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1246 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0xf6>
mov    -0x18(%rbp),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe90(%rip),%rdx
call   1040 <has_arg@plt>
test   %rax,%rax
jne    1190 <main+0x30>
lea    0xe82(%rip),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <has_arg@plt>
test   %rax,%rax
je     11b4 <main+0x54>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
mov    %r14,%rsi
call   1080 <bu_handle_version@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    11ad <main+0x4d>
cmp    $0x2,%ebp
jl     11d4 <main+0x74>
mov    (%r14),%rdi
call   1060 <bu_extra_argument@plt>
jmp    11a8 <main+0x48>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getlogin@plt>
test   %rax,%rax
je     11ec <main+0x8c>
mov    %rax,%rdi
call   1030 <puts@plt>
jmp    11ad <main+0x4d>
mov    (%r14),%rdi
call   1070 <perror@plt>
jmp    11a8 <main+0x48>

LLVM IR (-O0):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [14 x i8] c"Usage: whoami\00"
@.str.3 = [23 x i8] c"Print effected userid.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = load i8**, i8*** %5
%9 = call i64 @has_arg(i32 %7, i8** %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i64 @has_arg(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11, %2
%17 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %45
19: ; preds = %11
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i64 @bu_handle_version(i32 %20, i8** %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %3
br label %45
25: ; preds = %19
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @bu_extra_argument(i8* %31)
store i32 1, i32* %3
br label %45
33: ; preds = %25
%34 = call i8* (...) @getlogin()
store i8* %34, i8** %6
%35 = load i8*, i8** %6
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 @perror(i8* %40)
store i32 1, i32* %3
br label %45
42: ; preds = %33
%43 = load i8*, i8** %6
%44 = call i32 @puts(i8* %43)
store i32 0, i32* %3
br label %45
45: ; preds = %42, %37, %28, %24, %16
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [14 x i8] c"Usage: whoami\00"
@.str.3 = [23 x i8] c"Print effected userid.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i64 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5, %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %27
11: ; preds = %5
%12 = tail call i64 @bu_handle_version(i32 %0, i8** %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %11
%15 = icmp sgt i32 %0, 1
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = load i8*, i8** %1
%18 = tail call i32 @bu_extra_argument(i8* %17)
br label %27
19: ; preds = %14
%20 = tail call i8* (...) @getlogin()
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %1
%24 = tail call i32 @perror(i8* %23)
br label %27
25: ; preds = %19
%26 = tail call i32 @puts(i8* %20)
br label %27
27: ; preds = %22, %25, %11, %16, %8
%28 = phi i32 [ 1, %8 ], [ 1, %16 ], [ 0, %11 ], [ 1, %22 ], [ 0, %25 ]
ret i32 %28
}