#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_gecos;
  scalar_t__ pw_uid;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ _SC_GETPW_R_SIZE_MAX;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getpwnam_r(char *, struct passwd *, char *, size_t, struct passwd **);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
size_t sysconf(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct passwd pwd;
  struct passwd *result;
  char *buf;
  size_t bufsize;
  int s;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s username\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
  if (bufsize == -1)
    bufsize = 16384;
  buf = malloc(bufsize);
  if (buf == NULL) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }
  s = getpwnam_r(argv[1], &pwd, buf, bufsize, &result);
  if (result == NULL) {
    if (s == 0)
      printf("Not found\n");
    else {
      errno = s;
      perror("getpwnam_r");
    }
    exit(EXIT_FAILURE);
  }
  printf("Name: [%p] %s; UID: %ld\n", pwd.pw_gecos, pwd.pw_gecos,
         (long)pwd.pw_uid);
  char *p = buf;
  while (p && strlen(p) > 0) {
    printf("[%p] %s\n", p, p);
    p += strlen(p) + 1;
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ca <main+0x4a>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1090 <sysconf@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    11ef <main+0x6f>
movq   $0x4000,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1221 <main+0xa1>
lea    0xe06(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%r8
call   1070 <getpwnam_r@plt>
mov    %eax,-0x3c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    128f <main+0x10f>
cmpl   $0x0,-0x3c(%rbp)
jne    1269 <main+0xe9>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1281 <main+0x101>
mov    -0x3c(%rbp),%ecx
mov    0x2d5d(%rip),%rax
mov    %ecx,(%rax)
lea    0xdaa(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x48(%rbp)
mov    %al,-0x49(%rbp)
je     12d4 <main+0x154>
mov    -0x48(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
setg   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    12e4 <main+0x164>
jmp    1314 <main+0x194>
mov    -0x48(%rbp),%rsi
mov    -0x48(%rbp),%rdx
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    12b1 <main+0x131>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11d3 <main+0x43>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   10a0 <sysconf@plt>
cmp    $0xffffffffffffffff,%rax
mov    $0x4000,%r15d
cmovne %rax,%r15
mov    %r15,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
jne    11ed <main+0x5d>
lea    0xe43(%rip),%rdi
jmp    1229 <main+0x99>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe1a(%rip),%rsi
call   1060 <fprintf@plt>
jmp    122e <main+0x9e>
mov    %rax,%rbx
mov    0x8(%r14),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%r8
mov    %rax,%rdx
mov    %r15,%rcx
call   1080 <getpwnam_r@plt>
cmpq   $0x0,0x8(%rsp)
jne    123c <main+0xac>
test   %eax,%eax
je     12aa <main+0x11a>
mov    0x2db0(%rip),%rcx
mov    %eax,(%rcx)
lea    0xdf2(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%rcx
lea    0xdd9(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    129c <main+0x10c>
lea    0xdd4(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jg     1270 <main+0xe0>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xd97(%rip),%rdi
call   1030 <puts@plt>
jmp    122e <main+0x9e>

LLVM IR (-O0):
%struct.passwd = type { i8*, i64 }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s username\0A\00"
@EXIT_FAILURE = global i32 0
@_SC_GETPW_R_SIZE_MAX = global i32 0
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [11 x i8] c"Not found\0A\00"
@errno = global i32 0
@.str.3 = [11 x i8] c"getpwnam_r\00"
@.str.4 = [25 x i8] c"Name: [%p] %s; UID: %ld\0A\00"
@.str.5 = [9 x i8] c"[%p] %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.passwd
%7 = alloca %struct.passwd*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load i32, i32* @_SC_GETPW_R_SIZE_MAX
%24 = call i64 @sysconf(i32 %23)
store i64 %24, i64* %9
%25 = load i64, i64* %9
%26 = icmp eq i64 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %22
store i64 16384, i64* %9
br label %28
28: ; preds = %27, %22
%29 = load i64, i64* %9
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i8*, i8** %8
%42 = load i64, i64* %9
%43 = call i32 @getpwnam_r(i8* %40, %struct.passwd* %6, i8* %41, i64 %42, %struct.passwd** %7)
store i32 %43, i32* %10
%44 = load %struct.passwd*, %struct.passwd** %7
%45 = icmp eq %struct.passwd* %44, null
br i1 %45, label %46, label %57
46: ; preds = %37
%47 = load i32, i32* %10
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %54
51: ; preds = %46
%52 = load i32, i32* %10
store i32 %52, i32* @errno
%53 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %51, %49
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %37
%58 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 0
%61 = load i8*, i8** %60
%62 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 1
%63 = load i64, i64* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %59, i8* %61, i64 %63)
%65 = load i8*, i8** %8
store i8* %65, i8** %11
br label %66
66: ; preds = %75, %57
%67 = load i8*, i8** %11
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = load i8*, i8** %11
%71 = call i64 @strlen(i8* %70)
%72 = icmp sgt i64 %71, 0
br label %73
73: ; preds = %69, %66
%74 = phi i1 [ false, %66 ], [ %72, %69 ]
br i1 %74, label %75, label %84
75: ; preds = %73
%76 = load i8*, i8** %11
%77 = load i8*, i8** %11
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %76, i8* %77)
%79 = load i8*, i8** %11
%80 = call i64 @strlen(i8* %79)
%81 = add nsw i64 %80, 1
%82 = load i8*, i8** %11
%83 = getelementptr inbounds i8, i8* %82, i64 %81
store i8* %83, i8** %11
br label %66
84: ; preds = %73
%85 = load i32, i32* @EXIT_SUCCESS
%86 = call i32 @exit(i32 %85)
unreachable
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i64 }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s username\0A\00"
@EXIT_FAILURE = global i32 0
@_SC_GETPW_R_SIZE_MAX = global i32 0
@.str.1 = [7 x i8] c"malloc\00"
@errno = global i32 0
@.str.3 = [11 x i8] c"getpwnam_r\00"
@.str.4 = [25 x i8] c"Name: [%p] %s; UID: %ld\0A\00"
@.str.5 = [9 x i8] c"[%p] %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [10 x i8] c"Not found\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.passwd
%4 = alloca %struct.passwd*
%5 = bitcast %struct.passwd* %3 to i8*
%6 = bitcast %struct.passwd** %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* @_SC_GETPW_R_SIZE_MAX
%16 = tail call i64 @sysconf(i32 %15)
%17 = icmp eq i64 %16, -1
%18 = select i1 %17, i64 16384, i64 %16
%19 = tail call i8* @malloc(i64 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %14
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @getpwnam_r(i8* %27, %struct.passwd* %3, i8* %19, i64 %18, %struct.passwd** %4)
%29 = load %struct.passwd*, %struct.passwd** %4
%30 = icmp eq %struct.passwd* %29, null
br i1 %30, label %31, label %40
31: ; preds = %25
%32 = icmp eq i32 %28, 0
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %37
35: ; preds = %31
store i32 %28, i32* @errno
%36 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %33
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %25
%41 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%42 = load i8*, i8** %41
%43 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 1
%44 = load i64, i64* %43
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %42, i8* %42, i64 %44)
%46 = call i64 @strlen(i8* dereferenceable(1) %19)
%47 = icmp sgt i64 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %40, %48
%49 = phi i8* [ %53, %48 ], [ %19, %40 ]
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %49, i8* %49)
%51 = call i64 @strlen(i8* dereferenceable(1) %49)
%52 = add nsw i64 %51, 1
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = call i64 @strlen(i8* dereferenceable(1) %53)
%55 = icmp sgt i64 %54, 0
br i1 %55, label %48, label %56
56: ; preds = %48, %40
%57 = load i32, i32* @EXIT_SUCCESS
%58 = call i32 @exit(i32 %57)
unreachable
}