#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 */
typedef int /*<<< orphan*/ username;
struct passwd {
  int pw_uid;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct passwd *getpwnam(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char username[2048];
  struct passwd *pw;
  if (argc <= 1) {
    fprintf(stderr, "Usage: %s username\n", argv[0]);
    return 0;
  }
  snprintf(username, sizeof(username), "%s", (char *)argv[1]);
  if ((pw = getpwnam(username)) != NULL) {
    printf("%d\n", pw->pw_uid);
    return 0;
  } else {
    fprintf(stderr, "No such user: %s\n", username);
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     118b <main+0x4b>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe86(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120c <main+0xcc>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x800,%esi
lea    0xe6e(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x810(%rbp),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x818(%rbp)
cmp    $0x0,%rax
je     11e9 <main+0xa9>
mov    -0x818(%rbp),%rax
mov    (%rax),%esi
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120c <main+0xcc>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rdx
lea    0xe1b(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x800,%rsp
cmp    $0x1,%edi
jg     1169 <main+0x29>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xea0(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
jmp    11c0 <main+0x80>
mov    0x8(%rsi),%rcx
lea    0xea0(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
je     11a3 <main+0x63>
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11c0 <main+0x80>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
mov    %rsp,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x800,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s username\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [18 x i8] c"No such user: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2048 x i8]
%7 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %3
br label %34
16: ; preds = %2
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @snprintf(i8* %17, i32 2048, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%23 = call %struct.passwd* @getpwnam(i8* %22)
store %struct.passwd* %23, %struct.passwd** %7
%24 = icmp ne %struct.passwd* %23, null
br i1 %24, label %25, label %30
25: ; preds = %16
%26 = load %struct.passwd*, %struct.passwd** %7
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
store i32 0, i32* %3
br label %34
30: ; preds = %16
%31 = load i32, i32* @stderr
%32 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %32)
store i32 1, i32* %3
br label %34
34: ; preds = %30, %25, %10
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s username\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [18 x i8] c"No such user: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %23
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @snprintf(i8* %4, i32 2048, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call %struct.passwd* @getpwnam(i8* %4)
%15 = icmp eq %struct.passwd* %14, null
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %23
20: ; preds = %10
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %23
23: ; preds = %20, %16, %6
%24 = phi i32 [ 0, %6 ], [ 0, %16 ], [ 1, %20 ]
ret i32 %24
}