#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 */
struct passwd *getpwnam(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
void query(char *username) {
  struct passwd *pw;
  char response[4096];
  pw = getpwnam(username);
  if (pw) {
    sprintf(response,
            "Username: %s, uid: %d, gid: %d, gecos: %s, dir: %s, shell: %s\n\n",
            pw->pw_name, pw->pw_uid, pw->pw_gid, pw->pw_gecos, pw->pw_dir,
            pw->pw_shell);
  } else {
    sprintf(response,
            "%s does not exist on this system, according to getpwnam().\n\n",
            username);
  }
  printf(response);
}


x86 assembly (clang, -O0):
<query>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a8 <query+0x78>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r9
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r10
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
lea    0xe6d(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    11c1 <query+0x91>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x1010(%rbp),%rdi
call   1030 <printf@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<query>:
push   %rbx
sub    $0x1010,%rsp
mov    %rdi,%rbx
call   1040 <getpwnam@plt>
test   %rax,%rax
je     1170 <query+0x40>
mov    (%rax),%rdx
mov    0x8(%rax),%ecx
mov    0xc(%rax),%r8d
mov    0x10(%rax),%r9
movups 0x18(%rax),%xmm0
movups %xmm0,(%rsp)
lea    0xe9e(%rip),%rsi
lea    0x10(%rsp),%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    1186 <query+0x56>
lea    0xec9(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0x10(%rsp),%rdi
call   1030 <printf@plt>
add    $0x1010,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i32, i32, i8*, i8*, i8* }
@.str = [64 x i8] c"Username: %s, uid: %d, gid: %d, gecos: %s, dir: %s, shell: %s\0A\0A\00"
@.str.1 = [61 x i8] c"%s does not exist on this system, according to getpwnam().\0A\0A\00"
define void @query(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.passwd*
%4 = alloca [4096 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call %struct.passwd* @getpwnam(i8* %5)
store %struct.passwd* %6, %struct.passwd** %3
%7 = load %struct.passwd*, %struct.passwd** %3
%8 = icmp ne %struct.passwd* %7, null
br i1 %8, label %9, label %30
9: ; preds = %1
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%11 = load %struct.passwd*, %struct.passwd** %3
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = load %struct.passwd*, %struct.passwd** %3
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = load %struct.passwd*, %struct.passwd** %3
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 2
%19 = load i32, i32* %18
%20 = load %struct.passwd*, %struct.passwd** %3
%21 = getelementptr inbounds %struct.passwd, %struct.passwd* %20, i32 0, i32 3
%22 = load i8*, i8** %21
%23 = load %struct.passwd*, %struct.passwd** %3
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i32 0, i32 4
%25 = load i8*, i8** %24
%26 = load %struct.passwd*, %struct.passwd** %3
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %26, i32 0, i32 5
%28 = load i8*, i8** %27
%29 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %16, i32 %19, i8* %22, i8* %25, i8* %28)
br label %34
30: ; preds = %1
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%32 = load i8*, i8** %2
%33 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %30, %9
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%36 = call i32 @printf(i8* %35)
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i32, i32, i8*, i8*, i8* }
@.str = [64 x i8] c"Username: %s, uid: %d, gid: %d, gecos: %s, dir: %s, shell: %s\0A\0A\00"
@.str.1 = [61 x i8] c"%s does not exist on this system, according to getpwnam().\0A\0A\00"
define void @query(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = tail call %struct.passwd* @getpwnam(i8* %0)
%5 = icmp eq %struct.passwd* %4, null
br i1 %5, label %20, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 2
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 3
%14 = load i8*, i8** %13
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 4
%16 = load i8*, i8** %15
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 5
%18 = load i8*, i8** %17
%19 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %10, i32 %12, i8* %14, i8* %16, i8* %18)
br label %22
20: ; preds = %1
%21 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
22: ; preds = %20, %6
%23 = call i32 @printf(i8* %3)
ret void
}