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

/* Variables and functions */
struct passwd *getpwuid(scalar_t__);
int /*<<< orphan*/ printf(char *, char const *, int, char const *);
void printUser(const char *idname, uid_t uid) {
  struct passwd *pwd = getpwuid(uid);
  const char *name = "error";
  if (pwd != NULL)
    name = pwd->pw_name;
  printf("%s:\t%d <%s>\n", idname, (int)uid, name);
}


x86 assembly (clang, -O0):
<printUser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
lea    0xebc(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     115e <printUser+0x3e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printUser>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     113c <printUser+0x1c>
mov    (%rax),%rcx
jmp    1143 <printUser+0x23>
lea    0xebd(%rip),%rcx
lea    0xebc(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [6 x i8] c"error\00"
@.str.1 = [13 x i8] c"%s:\09%d <%s>\0A\00"
define void @printUser(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.passwd*
%6 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = call %struct.passwd* @getpwuid(i64 %7)
store %struct.passwd* %8, %struct.passwd** %5
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = load %struct.passwd*, %struct.passwd** %5
%10 = icmp ne %struct.passwd* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load %struct.passwd*, %struct.passwd** %5
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %12, i32 0, i32 0
%14 = load i8*, i8** %13
store i8* %14, i8** %6
br label %15
15: ; preds = %11, %2
%16 = load i8*, i8** %3
%17 = load i64, i64* %4
%18 = trunc i64 %17 to i32
%19 = load i8*, i8** %6
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 %18, i8* %19)
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [6 x i8] c"error\00"
@.str.1 = [13 x i8] c"%s:\09%d <%s>\0A\00"
define void @printUser(i8* %0, i64 %1) {
%3 = tail call %struct.passwd* @getpwuid(i64 %1)
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%7 = load i8*, i8** %6
br label %8
8: ; preds = %5, %2
%9 = phi i8* [ %7, %5 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = trunc i64 %1 to i32
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %10, i8* %9)
ret void
}