#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 dummy;
};

/* Variables and functions */
struct passwd *getpwnam(char const *);
struct passwd *getpwuid(long const);
long makeuid(char const *);
struct passwd *getuser(const char *username, const long fileuid) {
  long uidcheck = 0;
  struct passwd *local_user = NULL;
  if ((username == NULL) && (fileuid != -1)) {
    if ((local_user = getpwuid(fileuid)) != NULL) {
      return local_user;
    } else {
      return NULL;
    }
  } else {
    uidcheck = makeuid(username);
    if ((local_user = getpwnam(username)) != NULL) {
      return local_user;
    } else if ((uidcheck != 0) && ((local_user = getpwuid(uidcheck)) != NULL)) {
      return local_user;
    } else {
      return NULL;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<getuser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1197 <getuser+0x67>
cmpq   $0xffffffffffffffff,-0x18(%rbp)
je     1197 <getuser+0x67>
mov    -0x18(%rbp),%rdi
call   1030 <getpwuid@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     118a <getuser+0x5a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ff <getuser+0xcf>
movq   $0x0,-0x8(%rbp)
jmp    11ff <getuser+0xcf>
mov    -0x10(%rbp),%rdi
call   1050 <makeuid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getpwnam@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11c8 <getuser+0x98>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ff <getuser+0xcf>
cmpq   $0x0,-0x20(%rbp)
je     11f7 <getuser+0xc7>
mov    -0x20(%rbp),%rdi
call   1030 <getpwuid@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11f7 <getuser+0xc7>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ff <getuser+0xcf>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getuser>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1151 <getuser+0x21>
cmp    $0xffffffffffffffff,%rsi
je     1151 <getuser+0x21>
mov    %rsi,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <getpwuid@plt>
mov    %rbx,%rdi
call   1050 <makeuid@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <getpwnam@plt>
test   %rax,%rax
jne    117d <getuser+0x4d>
test   %r14,%r14
je     117b <getuser+0x4b>
mov    %r14,%rdi
call   1030 <getpwuid@plt>
test   %rax,%rax
jne    117d <getuser+0x4d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
define %struct.passwd* @getuser(i8* %0, i64 %1) {
%3 = alloca %struct.passwd*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca %struct.passwd*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 0, i64* %6
store %struct.passwd* null, %struct.passwd** %7
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %20
10: ; preds = %2
%11 = load i64, i64* %5
%12 = icmp ne i64 %11, -1
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i64, i64* %5
%15 = call %struct.passwd* @getpwuid(i64 %14)
store %struct.passwd* %15, %struct.passwd** %7
%16 = icmp ne %struct.passwd* %15, null
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load %struct.passwd*, %struct.passwd** %7
store %struct.passwd* %18, %struct.passwd** %3
br label %38
19: ; preds = %13
store %struct.passwd* null, %struct.passwd** %3
br label %38
20: ; preds = %10, %2
%21 = load i8*, i8** %4
%22 = call i64 @makeuid(i8* %21)
store i64 %22, i64* %6
%23 = load i8*, i8** %4
%24 = call %struct.passwd* @getpwnam(i8* %23)
store %struct.passwd* %24, %struct.passwd** %7
%25 = icmp ne %struct.passwd* %24, null
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = load %struct.passwd*, %struct.passwd** %7
store %struct.passwd* %27, %struct.passwd** %3
br label %38
28: ; preds = %20
%29 = load i64, i64* %6
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i64, i64* %6
%33 = call %struct.passwd* @getpwuid(i64 %32)
store %struct.passwd* %33, %struct.passwd** %7
%34 = icmp ne %struct.passwd* %33, null
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = load %struct.passwd*, %struct.passwd** %7
store %struct.passwd* %36, %struct.passwd** %3
br label %38
37: ; preds = %31, %28
store %struct.passwd* null, %struct.passwd** %3
br label %38
38: ; preds = %37, %35, %26, %19, %17
%39 = load %struct.passwd*, %struct.passwd** %3
ret %struct.passwd* %39
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
define %struct.passwd* @getuser(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp ne i64 %1, -1
%5 = and i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call %struct.passwd* @getpwuid(i64 %1)
br label %18
8: ; preds = %2
%9 = tail call i64 @makeuid(i8* %0)
%10 = tail call %struct.passwd* @getpwnam(i8* %0)
%11 = icmp eq %struct.passwd* %10, null
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = icmp eq i64 %9, 0
br i1 %13, label %17, label %14
14: ; preds = %12
%15 = tail call %struct.passwd* @getpwuid(i64 %9)
%16 = icmp eq %struct.passwd* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14, %12
br label %18
18: ; preds = %14, %8, %6, %17
%19 = phi %struct.passwd* [ null, %17 ], [ %7, %6 ], [ %10, %8 ], [ %15, %14 ]
ret %struct.passwd* %19
}