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

/* Variables and functions */
struct passwd *getpwuid(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
void uid_to_name(uid_t uid, char *user_id) {
  struct passwd *pwd;
  if ((pwd = getpwuid(uid)) == NULL) {
    sprintf(user_id, "%08d", uid);
  } else {
    strncpy(user_id, pwd->pw_name, 8);
  }
  return;
}


x86 assembly (clang, -O0):
<uid_to_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    116d <uid_to_name+0x3d>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe9d(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1181 <uid_to_name+0x51>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    $0x8,%edx
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uid_to_name>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1157 <uid_to_name+0x27>
mov    (%rax),%esi
mov    %rbx,%rdi
mov    $0x8,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <strncpy@plt>
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <sprintf@plt>

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

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