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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
char *basename(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int geteuid();
struct passwd *getpwuid(int);
int /*<<< orphan*/ puts(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct passwd *pw;
  uid_t uid;
  uid = geteuid();
  pw = getpwuid(uid);
  if (pw) {
    puts(pw->pw_name);
    return EXIT_SUCCESS;
  } else {
    fprintf(stderr, "%s: cannot get username for UID %u\n", basename(argv[0]),
            uid);
    return EXIT_FAILURE;
  }
}


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    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a3 <main+0x53>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <puts@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11dc <main+0x8c>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <basename@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe35(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-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
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     117c <main+0x2c>
mov    (%rax),%edi
call   1030 <puts@plt>
mov    0x2e56(%rip),%rax
jmp    11a7 <main+0x57>
mov    0x2e5d(%rip),%rax
mov    (%rax),%ebp
mov    (%r14),%rdi
call   1070 <basename@plt>
lea    0xe6c(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %ebx,%ecx
call   1060 <fprintf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"%s: cannot get username for UID %u\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.passwd*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @geteuid()
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = call %struct.passwd* @getpwuid(i32 %9)
store %struct.passwd* %10, %struct.passwd** %6
%11 = load %struct.passwd*, %struct.passwd** %6
%12 = icmp ne %struct.passwd* %11, null
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load %struct.passwd*, %struct.passwd** %6
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @puts(i32 %16)
%18 = load i32, i32* @EXIT_SUCCESS
store i32 %18, i32* %3
br label %28
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i8* @basename(i8* %23)
%25 = load i32, i32* %7
%26 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %24, i32 %25)
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %3
br label %28
28: ; preds = %19, %13
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"%s: cannot get username for UID %u\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @geteuid()
%4 = tail call %struct.passwd* @getpwuid(i32 %3)
%5 = icmp eq %struct.passwd* %4, null
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 @puts(i32 %8)
br label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i8* @basename(i8* %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %3)
br label %15
15: ; preds = %10, %6
%16 = phi i32* [ @EXIT_SUCCESS, %6 ], [ @EXIT_FAILURE, %10 ]
%17 = load i32, i32* %16
ret i32 %17
}