#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 pw_gid;
  int pw_uid;
};

/* Variables and functions */
struct passwd *getpwnam(char *);
int get_user_uid(char *user, int *oGid) {
  struct passwd *pwd;
  pwd = getpwnam(user);
  if (!pwd)
    return -1;
  if (oGid != NULL)
    *oGid = pwd->pw_gid;
  return pwd->pw_uid;
}


x86 assembly (clang, -O0):
<get_user_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1144 <get_user_uid+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    1165 <get_user_uid+0x55>
cmpq   $0x0,-0x18(%rbp)
je     115b <get_user_uid+0x4b>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_user_uid>:
push   %rbx
mov    %rsi,%rbx
call   1030 <getpwnam@plt>
test   %rax,%rax
je     112c <get_user_uid+0x1c>
test   %rbx,%rbx
je     1127 <get_user_uid+0x17>
mov    (%rax),%ecx
mov    %ecx,(%rbx)
mov    0x4(%rax),%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

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

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