#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 spwd {
  char *sp_namp;
  char *sp_pwdp;
};

/* 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 getspnam_r(char *, struct spwd *, char *, size_t, struct spwd **);
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 spwd pwd;
  struct spwd *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 = getspnam_r(argv[1], &pwd, buf, bufsize, &result);
  if (result == NULL) {
    if (s == 0)
      printf("Not found\n");
    else {
      errno = s;
      perror("getspnam_r");
    }
    exit(EXIT_FAILURE);
  }
  printf("Name: [%p] %s; Pwd [%p]: %s\n", pwd.sp_namp, pwd.sp_namp, pwd.sp_pwdp,
         pwd.sp_pwdp);
  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   1060 <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   1070 <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   1030 <getspnam_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   1050 <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
mov    -0x18(%rbp),%r8
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x48(%rbp)
mov    %al,-0x49(%rbp)
je     12d8 <main+0x158>
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
setg   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    12e8 <main+0x168>
jmp    1318 <main+0x198>
mov    -0x48(%rbp),%rsi
mov    -0x48(%rbp),%rdx
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    12b5 <main+0x135>
mov    0x2ca1(%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   1080 <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   1070 <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   1040 <getspnam_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
mov    %rcx,%r8
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jle    129c <main+0x10c>
lea    0xdd5(%rip),%r14
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jg     1270 <main+0xe0>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xd9b(%rip),%rdi
call   1030 <puts@plt>
jmp    122e <main+0x9e>

LLVM IR (-O0):
%struct.spwd = type { i8*, i8* }
@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"getspnam_r\00"
@.str.4 = [29 x i8] c"Name: [%p] %s; Pwd [%p]: %s\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.spwd
%7 = alloca %struct.spwd*
%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 @getspnam_r(i8* %40, %struct.spwd* %6, i8* %41, i64 %42, %struct.spwd** %7)
store i32 %43, i32* %10
%44 = load %struct.spwd*, %struct.spwd** %7
%45 = icmp eq %struct.spwd* %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.spwd, %struct.spwd* %6, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = getelementptr inbounds %struct.spwd, %struct.spwd* %6, i32 0, i32 0
%61 = load i8*, i8** %60
%62 = getelementptr inbounds %struct.spwd, %struct.spwd* %6, i32 0, i32 1
%63 = load i8*, i8** %62
%64 = getelementptr inbounds %struct.spwd, %struct.spwd* %6, i32 0, i32 1
%65 = load i8*, i8** %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %59, i8* %61, i8* %63, i8* %65)
%67 = load i8*, i8** %8
store i8* %67, i8** %11
br label %68
68: ; preds = %77, %57
%69 = load i8*, i8** %11
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %75
71: ; preds = %68
%72 = load i8*, i8** %11
%73 = call i64 @strlen(i8* %72)
%74 = icmp sgt i64 %73, 0
br label %75
75: ; preds = %71, %68
%76 = phi i1 [ false, %68 ], [ %74, %71 ]
br i1 %76, label %77, label %86
77: ; preds = %75
%78 = load i8*, i8** %11
%79 = load i8*, i8** %11
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %78, i8* %79)
%81 = load i8*, i8** %11
%82 = call i64 @strlen(i8* %81)
%83 = add nsw i64 %82, 1
%84 = load i8*, i8** %11
%85 = getelementptr inbounds i8, i8* %84, i64 %83
store i8* %85, i8** %11
br label %68
86: ; preds = %75
%87 = load i32, i32* @EXIT_SUCCESS
%88 = call i32 @exit(i32 %87)
unreachable
}

LLVM IR (-O2):
%struct.spwd = type { i8*, i8* }
@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"getspnam_r\00"
@.str.4 = [29 x i8] c"Name: [%p] %s; Pwd [%p]: %s\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.spwd
%4 = alloca %struct.spwd*
%5 = bitcast %struct.spwd* %3 to i8*
%6 = bitcast %struct.spwd** %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 @getspnam_r(i8* %27, %struct.spwd* %3, i8* %19, i64 %18, %struct.spwd** %4)
%29 = load %struct.spwd*, %struct.spwd** %4
%30 = icmp eq %struct.spwd* %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.spwd, %struct.spwd* %3, i64 0, i32 0
%42 = load i8*, i8** %41
%43 = getelementptr inbounds %struct.spwd, %struct.spwd* %3, i64 0, i32 1
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %42, i8* %42, i8* %44, i8* %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
}