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

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ errno;
struct passwd *getpwnam(char const *);
uid_t strtouid(const char *str) {
  struct passwd *pw = NULL;
  errno = 0;
  pw = getpwnam(str);
  if (errno) {
    return (uid_t)-1;
  } else if (!pw) {
    errno = EINVAL;
    return (uid_t)-1;
  }
  return pw->pw_uid;
}


x86 assembly (clang, -O0):
<strtouid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2eb5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <getpwnam@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e9a(%rip),%rax
cmpq   $0x0,(%rax)
je     115c <strtouid+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <strtouid+0x85>
cmpq   $0x0,-0x18(%rbp)
jne    1187 <strtouid+0x77>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rcx
mov    0x2e68(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <strtouid+0x85>
jmp    118c <strtouid+0x7c>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtouid>:
push   %rbx
mov    0x2ec8(%rip),%rbx
movq   $0x0,(%rbx)
call   1030 <getpwnam@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
cmpq   $0x0,(%rbx)
je     1134 <strtouid+0x24>
pop    %rbx
ret
test   %rcx,%rcx
je     113d <strtouid+0x2d>
mov    (%rcx),%eax
pop    %rbx
ret
mov    0x2e94(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@errno = global i64 0
@EINVAL = global i64 0
define i32 @strtouid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.passwd*
store i8* %0, i8** %3
store %struct.passwd* null, %struct.passwd** %4
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 ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %20
10: ; preds = %1
%11 = load %struct.passwd*, %struct.passwd** %4
%12 = icmp ne %struct.passwd* %11, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = load i64, i64* @EINVAL
store i64 %14, i64* @errno
store i32 -1, i32* %2
br label %20
15: ; preds = %10
br label %16
16: ; preds = %15
%17 = load %struct.passwd*, %struct.passwd** %4
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i32, i32* %18
store i32 %19, i32* %2
br label %20
20: ; preds = %16, %13, %9
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@errno = global i64 0
@EINVAL = global i64 0
define i32 @strtouid(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 %12
5: ; preds = %1
%6 = icmp eq %struct.passwd* %2, null
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = load i64, i64* @EINVAL
store i64 %8, i64* @errno
br label %12
9: ; preds = %5
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%11 = load i32, i32* %10
br label %12
12: ; preds = %1, %9, %7
%13 = phi i32 [ %11, %9 ], [ -1, %7 ], [ -1, %1 ]
ret i32 %13
}