#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 const *pw_name;
};

/* Variables and functions */
struct passwd *getpwuid(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
const char *uid_to_user(int uid) {
  static struct passwd *p;
  static char txt[64];
  p = getpwuid(uid);
  if (p)
    return p->pw_name;
  sprintf(txt, "%d", uid);
  return txt;
}


x86 assembly (clang, -O0):
<uid_to_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,0x2f06(%rip)
cmpq   $0x0,0x2efe(%rip)
je     115b <uid_to_user+0x3b>
mov    0x2ef1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    117c <uid_to_user+0x5c>
mov    -0xc(%rbp),%edx
lea    0x2eeb(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2ed8(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uid_to_user>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1030 <getpwuid@plt>
mov    %rax,0x2f0f(%rip)
test   %rax,%rax
je     113b <uid_to_user+0x1b>
mov    (%rax),%rbx
jmp    1153 <uid_to_user+0x33>
lea    0x2f0e(%rip),%rbx
lea    0xeb7(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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