#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*/ uid_t;
struct passwd {
  char *pw_name;
};

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *username_from_userid(uid_t uid) {
  struct passwd *pwd;
  pwd = getpwuid(uid);
  if (pwd == NULL) {
    if (errno == 0) {
      fprintf(stderr, "Account Not Found.\n");
      return NULL;
    } else {
      fprintf(stderr, "Err. getpwuid() Failed.\n");
      return NULL;
    }
  } else
    return pwd->pw_name;
}


x86 assembly (clang, -O0):
<username_from_userid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1197 <username_from_userid+0x77>
mov    0x2e8f(%rip),%rax
cmpq   $0x0,(%rax)
jne    1175 <username_from_userid+0x55>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <username_from_userid+0x82>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <username_from_userid+0x82>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<username_from_userid>:
push   %rax
call   1030 <getpwuid@plt>
test   %rax,%rax
je     1130 <username_from_userid+0x10>
mov    (%rax),%rax
pop    %rcx
ret
mov    0x2ea1(%rip),%rax
cmpq   $0x0,(%rax)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
je     114f <username_from_userid+0x2f>
lea    0xec7(%rip),%rsi
jmp    1156 <username_from_userid+0x36>
lea    0xeaa(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@errno = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"Account Not Found.\0A\00"
@.str.1 = [25 x i8] c"Err. getpwuid() Failed.\0A\00"
define i8* @username_from_userid(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.passwd*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call %struct.passwd* @getpwuid(i32 %5)
store %struct.passwd* %6, %struct.passwd** %4
%7 = load %struct.passwd*, %struct.passwd** %4
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %22
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %22
18: ; preds = %1
%19 = load %struct.passwd*, %struct.passwd** %4
%20 = getelementptr inbounds %struct.passwd, %struct.passwd* %19, i32 0, i32 0
%21 = load i8*, i8** %20
store i8* %21, i8** %2
br label %22
22: ; preds = %18, %15, %12
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@errno = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"Account Not Found.\0A\00"
@.str.1 = [25 x i8] c"Err. getpwuid() Failed.\0A\00"
define i8* @username_from_userid(i32 %0) {
%2 = tail call %struct.passwd* @getpwuid(i32 %0)
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
%7 = load i32, i32* @stderr
br i1 %6, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %15
10: ; preds = %4
%11 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %15
12: ; preds = %1
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%14 = load i8*, i8** %13
br label %15
15: ; preds = %12, %10, %8
%16 = phi i8* [ null, %8 ], [ null, %10 ], [ %14, %12 ]
ret i8* %16
}