#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 /*<<< orphan*/ uintmax_t;
typedef int /*<<< orphan*/ uid_t;
struct passwd {
  int /*<<< orphan*/ pw_uid;
};

/* Variables and functions */
int /*<<< orphan*/ errx(int, char *, char const *);
int getnum(char const *, int /*<<< orphan*/ *);
struct passwd *getpwnam(char const *);
uid_t getuser(const char *user) {
  uintmax_t num;
  struct passwd *pw;
  if ((pw = getpwnam(user)) != NULL)
    return pw->pw_uid;
  if (getnum(user, &num) == -1)
    errx(1, "no such user `%s'", user);
  return (uid_t)num;
}


x86 assembly (clang, -O0):
<getuser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1161 <getuser+0x31>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <getuser+0x62>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <getnum@plt>
cmp    $0xffffffff,%eax
jne    118c <getuser+0x5c>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe79(%rip),%rsi
call   1040 <errx@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getuser>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <getpwnam@plt>
test   %rax,%rax
je     1146 <getuser+0x16>
mov    %rax,%rbx
jmp    116f <getuser+0x3f>
lea    0x4(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <getnum@plt>
cmp    $0xffffffff,%eax
jne    116f <getuser+0x3f>
lea    0xe9e(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1040 <errx@plt>
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [18 x i8] c"no such user `%s'\00"
define i32 @getuser(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.passwd*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call %struct.passwd* @getpwnam(i8* %6)
store %struct.passwd* %7, %struct.passwd** %5
%8 = icmp ne %struct.passwd* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load %struct.passwd*, %struct.passwd** %5
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i32 0, i32 0
%12 = load i32, i32* %11
store i32 %12, i32* %2
br label %22
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @getnum(i8* %14, i32* %4)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = call i32 @errx(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %13
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %22
22: ; preds = %20, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str = [18 x i8] c"no such user `%s'\00"
define i32 @getuser(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call %struct.passwd* @getpwnam(i8* %0)
%5 = icmp eq %struct.passwd* %4, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 0
br label %13
8: ; preds = %1
%9 = call i32 @getnum(i8* %0, i32* %2)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @errx(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %8, %11, %6
%14 = phi i32* [ %7, %6 ], [ %2, %11 ], [ %2, %8 ]
%15 = load i32, i32* %14
ret i32 %15
}