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

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


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   1040 <getuid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1181 <main+0x51>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe89(%rip),%rdi
call   1050 <printf@plt>
jmp    1191 <main+0x61>
mov    -0x20(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     1154 <main+0x24>
mov    (%rax),%rsi
lea    0xeae(%rip),%rdi
jmp    115e <main+0x2e>
lea    0xea9(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* (...) @getuid()
%4 = tail call %struct.passwd* @getpwuid(i8* %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 i8*, i8** %7
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %12
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %12
12: ; preds = %10, %6
ret i32 0
}