#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 */
struct passwd *getpwnam(char const *);
long strtol(char const *, char **, int);
int parse_uid(const char *user, uid_t *u) {
  char *v;
  long l;
  l = strtol(user, &v, 10);
  if (v && !*v) {
    *u = (uid_t)l;
    return 1;
  } else {
    struct passwd *pw = getpwnam(user);
    if (pw) {
      *u = pw->pw_uid;
      return 1;
    }
  }
  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    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1175 <parse_uid+0x55>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1175 <parse_uid+0x55>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b3 <parse_uid+0x93>
mov    -0x10(%rbp),%rdi
call   1030 <getpwnam@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11a7 <parse_uid+0x87>
mov    -0x30(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b3 <parse_uid+0x93>
jmp    11ac <parse_uid+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
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
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     1145 <parse_uid+0x25>
cmpb   $0x0,(%rcx)
je     1165 <parse_uid+0x45>
mov    %rbx,%rdi
call   1030 <getpwnam@plt>
mov    %rax,%rcx
test   %rax,%rax
je     115b <parse_uid+0x3b>
mov    (%rcx),%rax
mov    %rax,(%r14)
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    116d <parse_uid+0x4d>
mov    %rax,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i64 }
define i32 @parse_uid(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.passwd*
store i8* %0, i8** %4
store i64* %1, i64** %5
%9 = load i8*, i8** %4
%10 = call i64 @strtol(i8* %9, i8** %6, i32 10)
store i64 %10, i64* %7
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i64, i64* %7
%19 = load i64*, i64** %5
store i64 %18, i64* %19
store i32 1, i32* %3
br label %32
20: ; preds = %13, %2
%21 = load i8*, i8** %4
%22 = call %struct.passwd* @getpwnam(i8* %21)
store %struct.passwd* %22, %struct.passwd** %8
%23 = load %struct.passwd*, %struct.passwd** %8
%24 = icmp ne %struct.passwd* %23, null
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load %struct.passwd*, %struct.passwd** %8
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %26, i32 0, i32 0
%28 = load i64, i64* %27
%29 = load i64*, i64** %5
store i64 %28, i64* %29
store i32 1, i32* %3
br label %32
30: ; preds = %20
br label %31
31: ; preds = %30
store i32 0, i32* %3
br label %32
32: ; preds = %31, %25, %17
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.passwd = type { i64 }
define i32 @parse_uid(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8
store i64 %5, i64* %1
br label %21
12: ; preds = %8, %2
%13 = tail call %struct.passwd* @getpwnam(i8* %0)
%14 = icmp eq %struct.passwd* %13, null
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i64 0, i32 0
%17 = load i64, i64* %16
store i64 %17, i64* %1
br label %18
18: ; preds = %12, %15
%19 = xor i1 %14, true
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %18, %11
%22 = phi i32 [ 1, %11 ], [ %20, %18 ]
ret i32 %22
}