#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*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ geteuid();
struct passwd *getpwuid(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(void) {
  register struct passwd *pw;
  register uid_t uid;
  uid = geteuid();
  pw = getpwuid(uid);
  if (pw) {
    write(STDOUT_FILENO, pw->pw_name, strlen(pw->pw_name));
    write(STDOUT_FILENO, "\n", 1);
    exit(0);
  }
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d2 <main+0x82>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
jne    1171 <main+0x21>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e78(%rip),%r14
mov    (%r14),%ebp
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r14),%edi
lea    0xe64(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i8* }
@STDOUT_FILENO = global i32 0
@.str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.passwd*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @geteuid()
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = call %struct.passwd* @getpwuid(i32 %5)
store %struct.passwd* %6, %struct.passwd** %2
%7 = load %struct.passwd*, %struct.passwd** %2
%8 = icmp ne %struct.passwd* %7, null
br i1 %8, label %9, label %22
9: ; preds = %0
%10 = load i32, i32* @STDOUT_FILENO
%11 = load %struct.passwd*, %struct.passwd** %2
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = load %struct.passwd*, %struct.passwd** %2
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = call i32 @strlen(i8* %16)
%18 = call i32 @write(i32 %10, i8* %13, i32 %17)
%19 = load i32, i32* @STDOUT_FILENO
%20 = call i32 @write(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %0
%23 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@STDOUT_FILENO = global i32 0
@.str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @geteuid()
%2 = tail call %struct.passwd* @getpwuid(i32 %1)
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %13, label %4
4: ; preds = %0
%5 = load i32, i32* @STDOUT_FILENO
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%7 = load i8*, i8** %6
%8 = tail call i32 @strlen(i8* %7)
%9 = tail call i32 @write(i32 %5, i8* %7, i32 %8)
%10 = load i32, i32* @STDOUT_FILENO
%11 = tail call i32 @write(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %0
%14 = tail call i32 @exit(i32 1)
unreachable
}