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

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void main(int argc, char *argv[]) {
  struct passwd *upw = getpwuid(getuid());
  if (upw) {
    write(STDOUT_FILENO, upw->pw_name, strlen(upw->pw_name));
    write(STDOUT_FILENO, "\n", 1);
    exit(0);
  }
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ce <main+0x7e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%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    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%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 <getuid@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 void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.passwd*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = call i32 (...) @getuid()
%7 = call %struct.passwd* @getpwuid(i32 %6)
store %struct.passwd* %7, %struct.passwd** %5
%8 = load %struct.passwd*, %struct.passwd** %5
%9 = icmp ne %struct.passwd* %8, null
br i1 %9, label %10, label %23
10: ; preds = %2
%11 = load i32, i32* @STDOUT_FILENO
%12 = load %struct.passwd*, %struct.passwd** %5
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %12, i32 0, i32 0
%14 = load i8*, i8** %13
%15 = load %struct.passwd*, %struct.passwd** %5
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i32 0, i32 0
%17 = load i8*, i8** %16
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @write(i32 %11, i8* %14, i32 %18)
%20 = load i32, i32* @STDOUT_FILENO
%21 = call i32 @write(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %2
%24 = 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 void @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getuid()
%4 = tail call %struct.passwd* @getpwuid(i32 %3)
%5 = icmp eq %struct.passwd* %4, null
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = load i32, i32* @STDOUT_FILENO
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = tail call i32 @write(i32 %7, i8* %9, i32 %10)
%12 = load i32, i32* @STDOUT_FILENO
%13 = tail call i32 @write(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = tail call i32 @exit(i32 1)
unreachable
}