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

/* Variables and functions */
int /*<<< orphan*/ geteuid();
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *cuserid(char *s) {
  register struct passwd *pwd;
  if ((pwd = getpwuid(geteuid())) == NULL) {
    if (s) {
      *s = '\0';
    }
    return (s);
  }
  if (s) {
    (void)strncpy(s, pwd->pw_name, 128);
    return (s);
  }
  return (pwd->pw_name);
}


x86 assembly (clang, -O0):
<cuserid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1177 <cuserid+0x47>
cmpq   $0x0,-0x10(%rbp)
je     116a <cuserid+0x3a>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11af <cuserid+0x7f>
cmpq   $0x0,-0x10(%rbp)
je     11a4 <cuserid+0x74>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11af <cuserid+0x7f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cuserid>:
push   %rbx
mov    %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),%rsi
test   %rbx,%rbx
je     1168 <cuserid+0x38>
mov    %rbx,%rdi
mov    $0x80,%edx
call   1030 <strncpy@plt>
jmp    116f <cuserid+0x3f>
test   %rbx,%rbx
je     116d <cuserid+0x3d>
movb   $0x0,(%rbx)
jmp    116f <cuserid+0x3f>
mov    %rsi,%rbx
jmp    116f <cuserid+0x3f>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

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

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