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

/* Variables and functions */
struct passwd *getpwuid(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, ...);
char *uid_rep(uid_t uid) {
  static char buf[200];
  struct passwd *pw = getpwuid(uid);
  if (pw)
    snprintf(buf, sizeof buf, "%d(%s)", uid, pw->pw_name);
  else
    snprintf(buf, sizeof buf, "%d", uid);
  return buf;
}


x86 assembly (clang, -O0):
<uid_rep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116b <uid_rep+0x4b>
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    (%rax),%r8
lea    0x2eed(%rip),%rdi
mov    $0xc8,%esi
lea    0xea1(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    1188 <uid_rep+0x68>
mov    -0x4(%rbp),%ecx
lea    0x2ecb(%rip),%rdi
mov    $0xc8,%esi
lea    0xe86(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    0x2eb1(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uid_rep>:
push   %rbx
mov    %edi,%ebx
call   1030 <getpwuid@plt>
test   %rax,%rax
je     114e <uid_rep+0x2e>
mov    (%rax),%r8
lea    0x2f09(%rip),%rdi
lea    0xec2(%rip),%rdx
mov    $0xc8,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    116a <uid_rep+0x4a>
lea    0x2eeb(%rip),%rdi
lea    0xeab(%rip),%rdx
mov    $0xc8,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0x2ecf(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@uid_rep.buf = internal global [200 x i8] zeroinitializer
@.str = [7 x i8] c"%d(%s)\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @uid_rep(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.passwd*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call %struct.passwd* @getpwuid(i32 %4)
store %struct.passwd* %5, %struct.passwd** %3
%6 = load %struct.passwd*, %struct.passwd** %3
%7 = icmp ne %struct.passwd* %6, null
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* %2
%10 = load %struct.passwd*, %struct.passwd** %3
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @uid_rep.buf, i64 0, i64 0), i32 200, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %12)
br label %17
14: ; preds = %1
%15 = load i32, i32* %2
%16 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @uid_rep.buf, i64 0, i64 0), i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %8
ret i8* getelementptr inbounds ([200 x i8], [200 x i8]* @uid_rep.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@uid_rep.buf = internal global [200 x i8] zeroinitializer
@.str = [7 x i8] c"%d(%s)\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @uid_rep(i32 %0) {
%2 = tail call %struct.passwd* @getpwuid(i32 %0)
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%6 = load i8*, i8** %5
%7 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @uid_rep.buf, i64 0, i64 0), i32 200, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %6)
br label %10
8: ; preds = %1
%9 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @uid_rep.buf, i64 0, i64 0), i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %10
10: ; preds = %8, %4
ret i8* getelementptr inbounds ([200 x i8], [200 x i8]* @uid_rep.buf, i64 0, i64 0)
}