#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);
  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)
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    11df <main+0x6f>
movq   $0x4000,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1211 <main+0xa1>
lea    0xe16(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dbe(%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    127f <main+0x10f>
cmpl   $0x0,-0x3c(%rbp)
jne    1259 <main+0xe9>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <main+0x101>
mov    -0x3c(%rbp),%ecx
mov    0x2d6d(%rip),%rax
mov    %ecx,(%rax)
lea    0xdba(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11c0 <main+0x40>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1090 <sysconf@plt>
cmp    $0xffffffffffffffff,%rax
mov    $0x4000,%ebx
cmovne %rax,%rbx
mov    %rbx,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
jne    11da <main+0x5a>
lea    0xe56(%rip),%rdi
jmp    120c <main+0x8c>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe2d(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1211 <main+0x91>
mov    0x8(%r14),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%r8
mov    %rax,%rdx
mov    %rbx,%rcx
call   1070 <getpwnam_r@plt>
cmpq   $0x0,(%rsp)
jne    121f <main+0x9f>
test   %eax,%eax
je     1245 <main+0xc5>
mov    0x2dcd(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe0f(%rip),%rdi
call   1080 <perror@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
lea    0xdf6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xdee(%rip),%rdi
call   1030 <puts@plt>
jmp    1211 <main+0x91>

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 = [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 = icmp eq i64 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %21
store i64 16384, i64* %9
br label %27
27: ; preds = %26, %21
%28 = load i64, i64* %9
%29 = call i8* @malloc(i64 %28)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %27
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = load i8*, i8** %8
%41 = load i64, i64* %9
%42 = call i32 @getpwnam_r(i8* %39, %struct.passwd* %6, i8* %40, i64 %41, %struct.passwd** %7)
store i32 %42, i32* %10
%43 = load %struct.passwd*, %struct.passwd** %7
%44 = icmp eq %struct.passwd* %43, null
br i1 %44, label %45, label %56
45: ; preds = %36
%46 = load i32, i32* %10
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %53
50: ; preds = %45
%51 = load i32, i32* %10
store i32 %51, i32* @errno
%52 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %50, %48
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %36
%57 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 0
%58 = load i8*, i8** %57
%59 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 1
%60 = load i64, i64* %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %58, i64 %60)
%62 = load i32, i32* @EXIT_SUCCESS
%63 = call i32 @exit(i32 %62)
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 = [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 = 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 ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %42, i64 %44)
%46 = load i32, i32* @EXIT_SUCCESS
%47 = call i32 @exit(i32 %46)
unreachable
}