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

/* Variables and functions */
int /*<<< orphan*/ geteuid();
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
char *cuserid(char *user_name) {
  static char userid[9];
  struct passwd *pw_entry;
  if (user_name == (char *)NULL)
    user_name = userid;
  pw_entry = getpwuid(geteuid());
  if (pw_entry == (struct passwd *)NULL) {
    *user_name = '\0';
    return ((char *)NULL);
  }
  strcpy(user_name, pw_entry->pw_name);
  return (user_name);
}


x86 assembly (clang, -O0):
<cuserid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1152 <cuserid+0x22>
lea    0x2eeb(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1183 <cuserid+0x53>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    119a <cuserid+0x6a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cuserid>:
push   %rbx
test   %rdi,%rdi
lea    0x2efe(%rip),%rbx
cmovne %rdi,%rbx
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     115e <cuserid+0x2e>
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    1163 <cuserid+0x33>
movb   $0x0,(%rbx)
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@cuserid.userid = internal global [9 x i8] zeroinitializer
define i8* @cuserid(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.passwd*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @cuserid.userid, i64 0, i64 0), i8** %3
br label %8
8: ; preds = %7, %1
%9 = call i32 (...) @geteuid()
%10 = call %struct.passwd* @getpwuid(i32 %9)
store %struct.passwd* %10, %struct.passwd** %4
%11 = load %struct.passwd*, %struct.passwd** %4
%12 = icmp eq %struct.passwd* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = load i8*, i8** %3
store i8 0, i8* %14
store i8* null, i8** %2
br label %22
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = load %struct.passwd*, %struct.passwd** %4
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @strcpy(i8* %16, i32 %19)
%21 = load i8*, i8** %3
store i8* %21, i8** %2
br label %22
22: ; preds = %15, %13
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@cuserid.userid = internal global [9 x i8] zeroinitializer
define i8* @cuserid(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = select i1 %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @cuserid.userid, i64 0, i64 0), i8* %0
%4 = tail call i32 (...) @geteuid()
%5 = tail call %struct.passwd* @getpwuid(i32 %4)
%6 = icmp eq %struct.passwd* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i8 0, i8* %3
br label %12
8: ; preds = %1
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @strcpy(i8* %3, i32 %10)
br label %12
12: ; preds = %8, %7
%13 = phi i8* [ null, %7 ], [ %3, %8 ]
ret i8* %13
}