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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *,
                           char *);
struct passwd *getpwnam(char *);
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int _getpwnam(char const *progname) {
  struct passwd *pw;
  printf("%s: Testing getpwnam()\n", progname);
  if ((pw = getpwnam("root")) == NULL) {
    fprintf(stderr, "%s: %s: %s\n", progname, "getpwnam", strerror(errno));
    return 2;
  }
  printf("%s: %s:%s:%u:%u:%s:%s:%s\n", progname, pw->pw_name, "*", pw->pw_uid,
         pw->pw_gid, pw->pw_gecos, pw->pw_dir, pw->pw_shell);
  if (pw->pw_uid != 0)
    return 4;
  return 0;
}


x86 assembly (clang, -O0):
<_getpwnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
call   1040 <getpwnam@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c3 <_getpwnam+0x83>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%r8
lea    0xe72(%rip),%rsi
lea    0xe77(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    123a <_getpwnam+0xfa>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r11
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%r10
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rax
lea    0xe35(%rip),%rdi
lea    0xe48(%rip),%rcx
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x0,0x8(%rax)
je     1233 <_getpwnam+0xf3>
movl   $0x4,-0x4(%rbp)
jmp    123a <_getpwnam+0xfa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_getpwnam>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0xeaf(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
call   1040 <getpwnam@plt>
test   %rax,%rax
je     11b1 <_getpwnam+0x71>
mov    %rax,%rbx
mov    (%rax),%rdx
mov    0x8(%rax),%r8d
mov    0xc(%rax),%r9d
movups 0x10(%rax),%xmm0
mov    0x20(%rax),%rax
mov    %rax,0x10(%rsp)
movups %xmm0,(%rsp)
lea    0xea0(%rip),%rdi
lea    0xeb3(%rip),%rcx
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
cmpl   $0x0,0x8(%rbx)
setne  %al
shl    $0x2,%eax
jmp    11e8 <_getpwnam+0xa8>
mov    0x2e28(%rip),%rax
mov    (%rax),%ebx
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe4e(%rip),%rsi
lea    0xe53(%rip),%rcx
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%r8
call   1050 <fprintf@plt>
mov    $0x2,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i32, i32, i8*, i8*, i8* }
@.str = [24 x i8] c"%s: Testing getpwnam()\0A\00"
@.str.1 = [5 x i8] c"root\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"%s: %s: %s\0A\00"
@.str.3 = [9 x i8] c"getpwnam\00"
@errno = global i32 0
@.str.4 = [26 x i8] c"%s: %s:%s:%u:%u:%s:%s:%s\0A\00"
@.str.5 = [2 x i8] c"*\00"
define i32 @_getpwnam(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.passwd*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store %struct.passwd* %7, %struct.passwd** %4
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %3
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %13)
store i32 2, i32* %2
br label %42
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = load %struct.passwd*, %struct.passwd** %4
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = load %struct.passwd*, %struct.passwd** %4
%21 = getelementptr inbounds %struct.passwd, %struct.passwd* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = load %struct.passwd*, %struct.passwd** %4
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i32 0, i32 2
%25 = load i32, i32* %24
%26 = load %struct.passwd*, %struct.passwd** %4
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %26, i32 0, i32 3
%28 = load i8*, i8** %27
%29 = load %struct.passwd*, %struct.passwd** %4
%30 = getelementptr inbounds %struct.passwd, %struct.passwd* %29, i32 0, i32 4
%31 = load i8*, i8** %30
%32 = load %struct.passwd*, %struct.passwd** %4
%33 = getelementptr inbounds %struct.passwd, %struct.passwd* %32, i32 0, i32 5
%34 = load i8*, i8** %33
%35 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %16, i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %22, i32 %25, i8* %28, i8* %31, i8* %34)
%36 = load %struct.passwd*, %struct.passwd** %4
%37 = getelementptr inbounds %struct.passwd, %struct.passwd* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %15
store i32 4, i32* %2
br label %42
41: ; preds = %15
store i32 0, i32* %2
br label %42
42: ; preds = %41, %40, %9
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i32, i32, i8*, i8*, i8* }
@.str = [24 x i8] c"%s: Testing getpwnam()\0A\00"
@.str.1 = [5 x i8] c"root\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"%s: %s: %s\0A\00"
@.str.3 = [9 x i8] c"getpwnam\00"
@errno = global i32 0
@.str.4 = [26 x i8] c"%s: %s:%s:%u:%u:%s:%s:%s\0A\00"
@.str.5 = [2 x i8] c"*\00"
define i32 @_getpwnam(i8* %0) {
%2 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %8)
br label %27
10: ; preds = %1
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 2
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 3
%18 = load i8*, i8** %17
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 4
%20 = load i8*, i8** %19
%21 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 5
%22 = load i8*, i8** %21
%23 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %14, i32 %16, i8* %18, i8* %20, i8* %22)
%24 = load i32, i32* %13
%25 = icmp eq i32 %24, 0
%26 = select i1 %25, i32 0, i32 4
br label %27
27: ; preds = %10, %5
%28 = phi i32 [ 2, %5 ], [ %26, %10 ]
ret i32 %28
}