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

/* Variables and functions */
int /*<<< orphan*/ fail(char *, char *);
struct passwd *getpwnam(char *);
scalar_t__ strtol(char *, char **, int /*<<< orphan*/);
uid_t touid(char *owner) {
  struct passwd *pw;
  uid_t uid;
  char *cp;
  pw = getpwnam(owner);
  if (pw)
    return pw->pw_uid;
  uid = strtol(owner, &cp, 0);
  if (uid == 0 && cp == owner)
    fail("cannot find uid for %s", owner);
  return uid;
}


x86 assembly (clang, -O0):
<touid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getpwnam@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1164 <touid+0x34>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <touid+0x78>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a0 <touid+0x70>
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11a0 <touid+0x70>
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdi
call   1030 <fail@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<touid>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <getpwnam@plt>
test   %rax,%rax
je     1147 <touid+0x17>
mov    (%rax),%rax
jmp    1173 <touid+0x43>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
test   %rax,%rax
jne    1173 <touid+0x43>
cmp    %rbx,0x8(%rsp)
jne    1173 <touid+0x43>
lea    0xe97(%rip),%rdi
mov    %rbx,%rsi
call   1030 <fail@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i64 }
@.str = [23 x i8] c"cannot find uid for %s\00"
define i64 @touid(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca %struct.passwd*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call %struct.passwd* @getpwnam(i8* %7)
store %struct.passwd* %8, %struct.passwd** %4
%9 = load %struct.passwd*, %struct.passwd** %4
%10 = icmp ne %struct.passwd* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load %struct.passwd*, %struct.passwd** %4
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %12, i32 0, i32 0
%14 = load i64, i64* %13
store i64 %14, i64* %2
br label %29
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i64 @strtol(i8* %16, i8** %6, i32 0)
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = load i8*, i8** %3
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i8*, i8** %3
%26 = call i32 @fail(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %20, %15
%28 = load i64, i64* %5
store i64 %28, i64* %2
br label %29
29: ; preds = %27, %11
%30 = load i64, i64* %2
ret i64 %30
}

LLVM IR (-O2):
%struct.passwd = type { i64 }
@.str = [23 x i8] c"cannot find uid for %s\00"
define i64 @touid(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call %struct.passwd* @getpwnam(i8* %0)
%5 = icmp eq %struct.passwd* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 0
%8 = load i64, i64* %7
br label %17
9: ; preds = %1
%10 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%11 = icmp eq i64 %10, 0
%12 = load i8*, i8** %2
%13 = icmp eq i8* %12, %0
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @fail(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %9, %15, %6
%18 = phi i64 [ %8, %6 ], [ 0, %15 ], [ %10, %9 ]
ret i64 %18
}