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

/* Variables and functions */
struct passwd *getpwuid(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
char *uid_to_name(uid_t uid) {
  struct passwd *pw = getpwuid(uid);
  static char tmp[64];
  if (!pw)
    sprintf(tmp, "%d", uid);
  else
    strncpy(tmp, pw->pw_name, sizeof(tmp));
  return tmp;
}


x86 assembly (clang, -O0):
<uid_to_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <uid_to_name+0x3d>
mov    -0x4(%rbp),%edx
lea    0x2ef4(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1184 <uid_to_name+0x54>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0x2ed6(%rip),%rdi
mov    $0x40,%edx
call   1030 <strncpy@plt>
lea    0x2ec5(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uid_to_name>:
push   %rbx
mov    %edi,%ebx
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1152 <uid_to_name+0x22>
mov    (%rax),%esi
lea    0x2f0a(%rip),%rdi
mov    $0x40,%edx
call   1030 <strncpy@plt>
jmp    1167 <uid_to_name+0x37>
lea    0x2ef7(%rip),%rdi
lea    0xea0(%rip),%rsi
mov    %ebx,%edx
call   1050 <sprintf@plt>
lea    0x2ee2(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@uid_to_name.tmp = internal global [64 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @uid_to_name(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 %11, label %8
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @uid_to_name.tmp, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %16
11: ; preds = %1
%12 = load %struct.passwd*, %struct.passwd** %3
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @strncpy(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @uid_to_name.tmp, i64 0, i64 0), i32 %14, i32 64)
br label %16
16: ; preds = %11, %8
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @uid_to_name.tmp, i64 0, i64 0)
}

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