#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 uid_t;
struct passwd {
  int pw_uid;
};

/* Variables and functions */
scalar_t__ errno;
struct passwd *getpwnam(char *);
int /*<<< orphan*/ pexit(char *);
uid_t uidFromUsername(char *username) {
  struct passwd *user;
  errno = 0;
  user = getpwnam(username);
  if (errno == 0) {
    if (user == NULL) {
      return -1;
    } else {
      return user->pw_uid;
    }
  } else {
    pexit("getpwnam");
    return -1;
  }
}


x86 assembly (clang, -O0):
<uidFromUsername>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ead(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <getpwnam@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e92(%rip),%rax
cmpq   $0x0,(%rax)
jne    117d <uidFromUsername+0x5d>
cmpq   $0x0,-0x18(%rbp)
jne    116f <uidFromUsername+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1190 <uidFromUsername+0x70>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1190 <uidFromUsername+0x70>
lea    0xe7c(%rip),%rdi
call   1040 <pexit@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uidFromUsername>:
push   %rbx
mov    0x2eb8(%rip),%rbx
movq   $0x0,(%rbx)
call   1030 <getpwnam@plt>
cmpq   $0x0,(%rbx)
je     114d <uidFromUsername+0x2d>
lea    0xebf(%rip),%rdi
call   1040 <pexit@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
test   %rax,%rax
je     1146 <uidFromUsername+0x26>
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@errno = global i64 0
@.str = [9 x i8] c"getpwnam\00"
define i32 @uidFromUsername(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.passwd*
store i8* %0, i8** %3
store i64 0, i64* @errno
%5 = load i8*, i8** %3
%6 = call %struct.passwd* @getpwnam(i8* %5)
store %struct.passwd* %6, %struct.passwd** %4
%7 = load i64, i64* @errno
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = load %struct.passwd*, %struct.passwd** %4
%11 = icmp eq %struct.passwd* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 -1, i32* %2
br label %19
13: ; preds = %9
%14 = load %struct.passwd*, %struct.passwd** %4
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 0
%16 = load i32, i32* %15
store i32 %16, i32* %2
br label %19
17: ; preds = %1
%18 = call i32 @pexit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %19
19: ; preds = %17, %13, %12
%20 = load i32, i32* %2
ret i32 %20
}

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