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

/* Variables and functions */
struct passwd *getpwnam(char const *const);
unsigned long strtoul(char const *const, char **, int /*<<< orphan*/);
const char *parse_uid(const char *restrict const str,
                      uid_t *restrict const ret) {
  struct passwd *passwd_data;
  char *endp;
  unsigned long num;
  static const char uidrange[] = "User ID out of range.";
  static const char uidexist[] = "User name does not exist.";
  num = strtoul(str, &endp, 0);
  if (*endp != '\0') {
    passwd_data = getpwnam(str);
    if (!passwd_data)
      return uidexist;
    num = passwd_data->pw_uid;
  }
  if (num > 0xfffffffeUL)
    return uidrange;
  *ret = num;
  return 0;
}


x86 assembly (clang, -O0):
<parse_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1186 <parse_uid+0x66>
mov    -0x10(%rbp),%rdi
call   1030 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117b <parse_uid+0x5b>
lea    0xeae(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <parse_uid+0x98>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    $0xfffffffe,%eax
cmp    %rax,-0x30(%rbp)
jbe    11a5 <parse_uid+0x85>
lea    0xe64(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <parse_uid+0x98>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_uid>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
je     114d <parse_uid+0x2d>
mov    %rbx,%rdi
call   1030 <getpwnam@plt>
test   %rax,%rax
je     1167 <parse_uid+0x47>
mov    (%rax),%rax
mov    $0xfffffffe,%ecx
cmp    %rcx,%rax
jbe    1160 <parse_uid+0x40>
lea    0xea2(%rip),%rax
jmp    116e <parse_uid+0x4e>
mov    %rax,(%r14)
xor    %eax,%eax
jmp    116e <parse_uid+0x4e>
lea    0xeb2(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i64 }
@parse_uid.uidrange = internal constant [22 x i8] c"User ID out of range.\00"
@parse_uid.uidexist = internal constant [26 x i8] c"User name does not exist.\00"
define i8* @parse_uid(i8* noalias %0, i64* noalias %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca %struct.passwd*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
%9 = load i8*, i8** %4
%10 = call i64 @strtoul(i8* %9, i8** %7, i32 0)
store i64 %10, i64* %8
%11 = load i8*, i8** %7
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call %struct.passwd* @getpwnam(i8* %16)
store %struct.passwd* %17, %struct.passwd** %6
%18 = load %struct.passwd*, %struct.passwd** %6
%19 = icmp ne %struct.passwd* %18, null
br i1 %19, label %21, label %20
20: ; preds = %15
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @parse_uid.uidexist, i64 0, i64 0), i8** %3
br label %32
21: ; preds = %15
%22 = load %struct.passwd*, %struct.passwd** %6
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i32 0, i32 0
%24 = load i64, i64* %23
store i64 %24, i64* %8
br label %25
25: ; preds = %21, %2
%26 = load i64, i64* %8
%27 = icmp ugt i64 %26, 4294967294
br i1 %27, label %28, label %29
28: ; preds = %25
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @parse_uid.uidrange, i64 0, i64 0), i8** %3
br label %32
29: ; preds = %25
%30 = load i64, i64* %8
%31 = load i64*, i64** %5
store i64 %30, i64* %31
store i8* null, i8** %3
br label %32
32: ; preds = %29, %28, %20
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
%struct.passwd = type { i64 }
@parse_uid.uidrange = internal constant [22 x i8] c"User ID out of range.\00"
@parse_uid.uidexist = internal constant [26 x i8] c"User name does not exist.\00"
define i8* @parse_uid(i8* noalias %0, i64* noalias nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtoul(i8* %0, i8** %3, i32 0)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = tail call %struct.passwd* @getpwnam(i8* %0)
%11 = icmp eq %struct.passwd* %10, null
br i1 %11, label %19, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i64 0, i32 0
%14 = load i64, i64* %13
br label %15
15: ; preds = %12, %2
%16 = phi i64 [ %14, %12 ], [ %5, %2 ]
%17 = icmp ugt i64 %16, 4294967294
br i1 %17, label %19, label %18
18: ; preds = %15
store i64 %16, i64* %1
br label %19
19: ; preds = %15, %9, %18
%20 = phi i8* [ null, %18 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @parse_uid.uidexist, i64 0, i64 0), %9 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @parse_uid.uidrange, i64 0, i64 0), %15 ]
ret i8* %20
}