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

/* Variables and functions */
int /*<<< orphan*/ geteuid();
int getpwuid_r(int /*<<< orphan*/, struct passwd *, char *, int,
               struct passwd **);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  int res;
  uid_t uid = geteuid();
  struct passwd pwd, *result;
  char buf[1024];
  if (0 != (res = getpwuid_r(uid, &pwd, buf, 1024, &result))) {
    return res;
  }
  printf("%s\n", pwd.pw_name);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x430(%rbp),%rdx
lea    -0x20(%rbp),%rsi
mov    $0x400,%ecx
lea    -0x28(%rbp),%r8
call   1030 <getpwuid_r@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
je     1189 <main+0x59>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <main+0x70>
mov    -0x20(%rbp),%rsi
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x410,%rsp
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %rsp,%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%r8
mov    %eax,%edi
mov    $0x400,%ecx
call   1030 <getpwuid_r@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    116e <main+0x3e>
mov    (%rsp),%rsi
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x410,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [4 x i8] c"%s\0A\00"
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
%9 = alloca %struct.passwd*
%10 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @geteuid()
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%14 = call i32 @getpwuid_r(i32 %12, %struct.passwd* %8, i8* %13, i32 1024, %struct.passwd** %9)
store i32 %14, i32* %6
%15 = icmp ne i32 0, %14
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32, i32* %6
store i32 %17, i32* %3
br label %22
18: ; preds = %2
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 0, i32* %3
br label %22
22: ; preds = %18, %16
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.passwd
%4 = alloca %struct.passwd*
%5 = alloca [1024 x i8]
%6 = tail call i32 (...) @geteuid()
%7 = bitcast %struct.passwd* %3 to i8*
%8 = bitcast %struct.passwd** %4 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = call i32 @getpwuid_r(i32 %6, %struct.passwd* %3, i8* %9, i32 1024, %struct.passwd** %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %2, %12
ret i32 %10
}