#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;
};

/* Variables and functions */
int geteuid();
struct passwd *getpwuid(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  uid_t uid = -1;
  struct passwd *pw = NULL;
  uid = geteuid();
  if (uid != -1) {
    pw = getpwuid(uid);
    if (pw == NULL) {
      perror("");
      return -1;
    }
    printf("%s\n", pw->pw_name);
    return 0;
  }
  perror("");
  return -1;
}


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)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11c7 <main+0x87>
mov    -0x14(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a8 <main+0x68>
lea    0xe6c(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <main+0x9a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11da <main+0x9a>
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <geteuid@plt>
cmp    $0xffffffff,%eax
je     116c <main+0x2c>
mov    %eax,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     116c <main+0x2c>
mov    (%rax),%rsi
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe90(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

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

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