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

/* Variables and functions */
char *_utoa(int /*<<< orphan*/);
struct passwd *getpwuid(int /*<<< orphan*/);
char *utils_strdup(scalar_t__ *);
char *linux_map_uid(uid_t uid) {
  char *name = NULL;
  struct passwd *pw = getpwuid(uid);
  if (pw && pw->pw_name && *pw->pw_name) {
    name = utils_strdup(pw->pw_name);
  } else {
    name = _utoa(uid);
  }
  return name;
}


x86 assembly (clang, -O0):
<linux_map_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118e <linux_map_uid+0x5e>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     118e <linux_map_uid+0x5e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
je     118e <linux_map_uid+0x5e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <utils_strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    119a <linux_map_uid+0x6a>
mov    -0x4(%rbp),%edi
call   1050 <_utoa@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linux_map_uid>:
push   %rbx
mov    %edi,%ebx
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1151 <linux_map_uid+0x21>
mov    (%rax),%rdi
test   %rdi,%rdi
je     1151 <linux_map_uid+0x21>
cmpq   $0x0,(%rdi)
je     1151 <linux_map_uid+0x21>
pop    %rbx
jmp    1030 <utils_strdup@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1050 <_utoa@plt>

LLVM IR (-O0):
%struct.passwd = type { i64* }
define i8* @linux_map_uid(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.passwd*
store i32 %0, i32* %2
store i8* null, i8** %3
%5 = load i32, i32* %2
%6 = call %struct.passwd* @getpwuid(i32 %5)
store %struct.passwd* %6, %struct.passwd** %4
%7 = load %struct.passwd*, %struct.passwd** %4
%8 = icmp ne %struct.passwd* %7, null
br i1 %8, label %9, label %25
9: ; preds = %1
%10 = load %struct.passwd*, %struct.passwd** %4
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i32 0, i32 0
%12 = load i64*, i64** %11
%13 = icmp ne i64* %12, null
br i1 %13, label %14, label %25
14: ; preds = %9
%15 = load %struct.passwd*, %struct.passwd** %4
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i32 0, i32 0
%17 = load i64*, i64** %16
%18 = load i64, i64* %17
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load %struct.passwd*, %struct.passwd** %4
%22 = getelementptr inbounds %struct.passwd, %struct.passwd* %21, i32 0, i32 0
%23 = load i64*, i64** %22
%24 = call i8* @utils_strdup(i64* %23)
store i8* %24, i8** %3
br label %28
25: ; preds = %14, %9, %1
%26 = load i32, i32* %2
%27 = call i8* @_utoa(i32 %26)
store i8* %27, i8** %3
br label %28
28: ; preds = %25, %20
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
%struct.passwd = type { i64* }
define i8* @linux_map_uid(i32 %0) {
%2 = tail call %struct.passwd* @getpwuid(i32 %0)
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%6 = load i64*, i64** %5
%7 = icmp eq i64* %6, null
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = load i64, i64* %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i8* @utils_strdup(i64* %6)
br label %15
13: ; preds = %8, %4, %1
%14 = tail call i8* @_utoa(i32 %0)
br label %15
15: ; preds = %13, %11
%16 = phi i8* [ %12, %11 ], [ %14, %13 ]
ret i8* %16
}