#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;
  char *pw_passwd;
  int pw_uid;
  int pw_gid;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
};

/* Variables and functions */
struct passwd *getpwnam(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main() {
  struct passwd *pw = getpwnam("fnord");
  if (!pw)
    pw = getpwnam("alias");
  if (!pw)
    pw = getpwnam("nobody");
  if (!pw)
    pw = getpwnam("root");
  if (!pw) {
    puts("not found");
    return 0;
  }
  printf("name %s\npassword %s\nuid %u\ngid %u\ngecos %s\ndir %s\nshell %s\n",
         pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid, pw->pw_gecos,
         pw->pw_dir, pw->pw_shell);
  pw = getpwnam("doesNOThopefullnotexistsdar3245235wrafsdsfsdpl");
  if (pw)
    printf("getpwnam(\"doesNOThopefullnotexistsdar3245235wrafsdsfsdpl\" did "
           "not return null\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116a <main+0x3a>
lea    0xea5(%rip),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1185 <main+0x55>
lea    0xe90(%rip),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <main+0x70>
lea    0xe7c(%rip),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <main+0x93>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    1240 <main+0x110>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r9
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%r10
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
lea    0xe22(%rip),%rdi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe47(%rip),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1239 <main+0x109>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xec5(%rip),%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
jne    1178 <main+0x48>
lea    0xeba(%rip),%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
jne    1178 <main+0x48>
lea    0xeaf(%rip),%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
jne    1178 <main+0x48>
lea    0xea5(%rip),%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
je     11c4 <main+0x94>
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    0x10(%rax),%ecx
mov    0x14(%rax),%r8d
mov    0x18(%rax),%r9
movups 0x20(%rax),%xmm0
movups %xmm0,(%rsp)
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb7(%rip),%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
je     11bd <main+0x8d>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe4d(%rip),%rdi
jmp    11b8 <main+0x88>

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i32, i32, i8*, i8*, i8* }
@.str = [6 x i8] c"fnord\00"
@.str.1 = [6 x i8] c"alias\00"
@.str.2 = [7 x i8] c"nobody\00"
@.str.3 = [5 x i8] c"root\00"
@.str.4 = [10 x i8] c"not found\00"
@.str.5 = [60 x i8] c"name %s\0Apassword %s\0Auid %u\0Agid %u\0Agecos %s\0Adir %s\0Ashell %s\0A\00"
@.str.6 = [47 x i8] c"doesNOThopefullnotexistsdar3245235wrafsdsfsdpl\00"
@.str.7 = [79 x i8] c"getpwnam(\22doesNOThopefullnotexistsdar3245235wrafsdsfsdpl\22 did not return null\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.passwd*
store i32 0, i32* %1
%3 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store %struct.passwd* %3, %struct.passwd** %2
%4 = load %struct.passwd*, %struct.passwd** %2
%5 = icmp ne %struct.passwd* %4, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store %struct.passwd* %7, %struct.passwd** %2
br label %8
8: ; preds = %6, %0
%9 = load %struct.passwd*, %struct.passwd** %2
%10 = icmp ne %struct.passwd* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store %struct.passwd* %12, %struct.passwd** %2
br label %13
13: ; preds = %11, %8
%14 = load %struct.passwd*, %struct.passwd** %2
%15 = icmp ne %struct.passwd* %14, null
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store %struct.passwd* %17, %struct.passwd** %2
br label %18
18: ; preds = %16, %13
%19 = load %struct.passwd*, %struct.passwd** %2
%20 = icmp ne %struct.passwd* %19, null
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %52
23: ; preds = %18
%24 = load %struct.passwd*, %struct.passwd** %2
%25 = getelementptr inbounds %struct.passwd, %struct.passwd* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = load %struct.passwd*, %struct.passwd** %2
%28 = getelementptr inbounds %struct.passwd, %struct.passwd* %27, i32 0, i32 1
%29 = load i8*, i8** %28
%30 = load %struct.passwd*, %struct.passwd** %2
%31 = getelementptr inbounds %struct.passwd, %struct.passwd* %30, i32 0, i32 2
%32 = load i32, i32* %31
%33 = load %struct.passwd*, %struct.passwd** %2
%34 = getelementptr inbounds %struct.passwd, %struct.passwd* %33, i32 0, i32 3
%35 = load i32, i32* %34
%36 = load %struct.passwd*, %struct.passwd** %2
%37 = getelementptr inbounds %struct.passwd, %struct.passwd* %36, i32 0, i32 4
%38 = load i8*, i8** %37
%39 = load %struct.passwd*, %struct.passwd** %2
%40 = getelementptr inbounds %struct.passwd, %struct.passwd* %39, i32 0, i32 5
%41 = load i8*, i8** %40
%42 = load %struct.passwd*, %struct.passwd** %2
%43 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i32 0, i32 6
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %26, i8* %29, i32 %32, i32 %35, i8* %38, i8* %41, i8* %44)
%46 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0))
store %struct.passwd* %46, %struct.passwd** %2
%47 = load %struct.passwd*, %struct.passwd** %2
%48 = icmp ne %struct.passwd* %47, null
br i1 %48, label %49, label %51
49: ; preds = %23
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.7, i64 0, i64 0))
br label %51
51: ; preds = %49, %23
store i32 0, i32* %1
br label %52
52: ; preds = %51, %21
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i32, i32, i8*, i8*, i8* }
@.str = [6 x i8] c"fnord\00"
@.str.1 = [6 x i8] c"alias\00"
@.str.2 = [7 x i8] c"nobody\00"
@.str.3 = [5 x i8] c"root\00"
@.str.4 = [10 x i8] c"not found\00"
@.str.5 = [60 x i8] c"name %s\0Apassword %s\0Auid %u\0Agid %u\0Agecos %s\0Adir %s\0Ashell %s\0A\00"
@.str.6 = [47 x i8] c"doesNOThopefullnotexistsdar3245235wrafsdsfsdpl\00"
@str = [78 x i8] c"getpwnam(\22doesNOThopefullnotexistsdar3245235wrafsdsfsdpl\22 did not return null\00"
define i32 @main() {
%1 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq %struct.passwd* %1, null
br i1 %2, label %3, label %14
3: ; preds = %0
%4 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq %struct.passwd* %4, null
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq %struct.passwd* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %35
14: ; preds = %0, %3, %6, %9
%15 = phi %struct.passwd* [ %10, %9 ], [ %7, %6 ], [ %4, %3 ], [ %1, %0 ]
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i64 0, i32 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i64 0, i32 2
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i64 0, i32 3
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i64 0, i32 4
%25 = load i8*, i8** %24
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i64 0, i32 5
%27 = load i8*, i8** %26
%28 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i64 0, i32 6
%29 = load i8*, i8** %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %17, i8* %19, i32 %21, i32 %23, i8* %25, i8* %27, i8* %29)
%31 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0))
%32 = icmp eq %struct.passwd* %31, null
br i1 %32, label %35, label %33
33: ; preds = %14
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %14, %33, %12
ret i32 0
}