#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;
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);
  printf("%ld\n", bufsize);
  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: %s; UID: %ld\n", pwd.pw_gecos, (long)pwd.pw_uid);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ba <main+0x4a>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    11f1 <main+0x81>
movq   $0x4000,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1223 <main+0xb3>
lea    0xe04(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1090 <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   1060 <getpwnam_r@plt>
mov    %eax,-0x3c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1291 <main+0x121>
cmpl   $0x0,-0x3c(%rbp)
jne    126b <main+0xfb>
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1283 <main+0x113>
mov    -0x3c(%rbp),%ecx
mov    0x2d5b(%rip),%rax
mov    %ecx,(%rax)
lea    0xda8(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11d7 <main+0x57>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1090 <sysconf@plt>
mov    %rax,%rbx
lea    0xe8c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0xffffffffffffffff,%rbx
mov    $0x4000,%r15d
cmovne %rbx,%r15
mov    %r15,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
jne    11f1 <main+0x71>
lea    0xe3f(%rip),%rdi
jmp    1226 <main+0xa6>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe16(%rip),%rsi
call   1050 <fprintf@plt>
jmp    122b <main+0xab>
mov    0x8(%r14),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%r8
mov    %rax,%rdx
mov    %r15,%rcx
call   1070 <getpwnam_r@plt>
cmpq   $0x0,0x8(%rsp)
jne    1239 <main+0xb9>
test   %eax,%eax
je     125f <main+0xdf>
mov    0x2db3(%rip),%rcx
mov    %eax,(%rcx)
lea    0xdf5(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xdd4(%rip),%rdi
call   1030 <puts@plt>
jmp    122b <main+0xab>

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 = [5 x i8] c"%ld\0A\00"
@.str.2 = [7 x i8] c"malloc\00"
@.str.3 = [11 x i8] c"Not found\0A\00"
@errno = global i32 0
@.str.4 = [11 x i8] c"getpwnam_r\00"
@.str.5 = [20 x i8] c"Name: %s; UID: %ld\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i32, i32* @_SC_GETPW_R_SIZE_MAX
%23 = call i64 @sysconf(i32 %22)
store i64 %23, i64* %9
%24 = load i64, i64* %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %24)
%26 = load i64, i64* %9
%27 = icmp eq i64 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %21
store i64 16384, i64* %9
br label %29
29: ; preds = %28, %21
%30 = load i64, i64* %9
%31 = call i8* @malloc(i64 %30)
store i8* %31, i8** %8
%32 = load i8*, i8** %8
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %29
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i8*, i8** %8
%43 = load i64, i64* %9
%44 = call i32 @getpwnam_r(i8* %41, %struct.passwd* %6, i8* %42, i64 %43, %struct.passwd** %7)
store i32 %44, i32* %10
%45 = load %struct.passwd*, %struct.passwd** %7
%46 = icmp eq %struct.passwd* %45, null
br i1 %46, label %47, label %58
47: ; preds = %38
%48 = load i32, i32* %10
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %55
52: ; preds = %47
%53 = load i32, i32* %10
store i32 %53, i32* @errno
%54 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %52, %50
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %38
%59 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 0
%60 = load i8*, i8** %59
%61 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 1
%62 = load i64, i64* %61
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %60, i64 %62)
%64 = load i32, i32* @EXIT_SUCCESS
%65 = call i32 @exit(i32 %64)
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 = [5 x i8] c"%ld\0A\00"
@.str.2 = [7 x i8] c"malloc\00"
@errno = global i32 0
@.str.4 = [11 x i8] c"getpwnam_r\00"
@.str.5 = [20 x i8] c"Name: %s; UID: %ld\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 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %16)
%18 = icmp eq i64 %16, -1
%19 = select i1 %18, i64 16384, i64 %16
%20 = tail call i8* @malloc(i64 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %14
%23 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %14
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @getpwnam_r(i8* %28, %struct.passwd* %3, i8* %20, i64 %19, %struct.passwd** %4)
%30 = load %struct.passwd*, %struct.passwd** %4
%31 = icmp eq %struct.passwd* %30, null
br i1 %31, label %32, label %41
32: ; preds = %26
%33 = icmp eq i32 %29, 0
br i1 %33, label %34, label %36
34: ; preds = %32
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %38
36: ; preds = %32
store i32 %29, i32* @errno
%37 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %34
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %26
%42 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%43 = load i8*, i8** %42
%44 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 1
%45 = load i64, i64* %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %43, i64 %45)
%47 = load i32, i32* @EXIT_SUCCESS
%48 = call i32 @exit(i32 %47)
unreachable
}