#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 */
int /*<<< orphan*/ atol(char *);
int /*<<< orphan*/ exit(int);
struct passwd *getpwnam(char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, char *, int);
uid_t str2uid(char *str, int line_num) {
  struct passwd *pw;
  if (isdigit(str[0]))
    return (uid_t)atol(str);
  if (!(pw = getpwnam(str))) {
    printf("# ERROR # Invalid uid '%s' reading line %d\n", str, line_num);
    exit(255);
  }
  return pw->pw_uid;
}


x86 assembly (clang, -O0):
<str2uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1186 <str2uid+0x36>
mov    -0x10(%rbp),%rdi
call   1060 <atol@plt>
mov    %eax,-0x4(%rbp)
jmp    11c3 <str2uid+0x73>
mov    -0x10(%rbp),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ba <str2uid+0x6a>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    $0xff,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2uid>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1173 <str2uid+0x23>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <atol@plt>
mov    %rbx,%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
je     1189 <str2uid+0x39>
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    $0xff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [44 x i8] c"# ERROR # Invalid uid '%s' reading line %d\0A\00"
define i32 @str2uid(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 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = call i64 @isdigit(i8 signext %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @atol(i8* %13)
store i32 %14, i32* %3
br label %28
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call %struct.passwd* @getpwnam(i8* %16)
store %struct.passwd* %17, %struct.passwd** %6
%18 = icmp ne %struct.passwd* %17, null
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %21)
%23 = call i32 @exit(i32 255)
unreachable
24: ; preds = %15
%25 = load %struct.passwd*, %struct.passwd** %6
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i32 0, i32 0
%27 = load i32, i32* %26
store i32 %27, i32* %3
br label %28
28: ; preds = %24, %12
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str = [44 x i8] c"# ERROR # Invalid uid '%s' reading line %d\0A\00"
define i32 @str2uid(i8* %0, i32 %1) {
%3 = load i8, i8* %0
%4 = tail call i64 @isdigit(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @atol(i8* %0)
br label %17
8: ; preds = %2
%9 = tail call %struct.passwd* @getpwnam(i8* %0)
%10 = icmp eq %struct.passwd* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%13 = tail call i32 @exit(i32 255)
unreachable
14: ; preds = %8
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i64 0, i32 0
%16 = load i32, i32* %15
br label %17
17: ; preds = %14, %6
%18 = phi i32 [ %7, %6 ], [ %16, %14 ]
ret i32 %18
}