#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*/ atoi(char const *);
struct passwd *getpwnam(char const *);
scalar_t__ isdigit(char const);
int get_uid(const char user[], uid_t *uid) {
  if (isdigit(user[0])) {
    *uid = atoi(user);
  } else {
    struct passwd *p;
    p = getpwnam(user);
    if (p == NULL)
      return 1;
    *uid = p->pw_uid;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     116c <get_uid+0x3c>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    119c <get_uid+0x6c>
mov    -0x10(%rbp),%rdi
call   1040 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <get_uid+0x60>
movl   $0x1,-0x4(%rbp)
jmp    11a3 <get_uid+0x73>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uid>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     1151 <get_uid+0x21>
call   1050 <atoi@plt>
jmp    115d <get_uid+0x2d>
call   1040 <getpwnam@plt>
test   %rax,%rax
je     116a <get_uid+0x3a>
mov    (%rax),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%eax
jmp    1162 <get_uid+0x32>

LLVM IR (-O0):
%struct.passwd = type { i32 }
define i32 @get_uid(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 %16
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @atoi(i8* %13)
%15 = load i32*, i32** %5
store i32 %14, i32* %15
br label %27
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call %struct.passwd* @getpwnam(i8* %17)
store %struct.passwd* %18, %struct.passwd** %6
%19 = load %struct.passwd*, %struct.passwd** %6
%20 = icmp eq %struct.passwd* %19, null
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 1, i32* %3
br label %28
22: ; preds = %16
%23 = load %struct.passwd*, %struct.passwd** %6
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = load i32*, i32** %5
store i32 %25, i32* %26
br label %27
27: ; preds = %22, %12
store i32 0, i32* %3
br label %28
28: ; preds = %27, %21
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
define i32 @get_uid(i8* nocapture %0, i32* nocapture writeonly %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 @atoi(i8* %0)
br label %14
8: ; preds = %2
%9 = tail call %struct.passwd* @getpwnam(i8* %0)
%10 = icmp eq %struct.passwd* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i64 0, i32 0
%13 = load i32, i32* %12
br label %14
14: ; preds = %11, %6
%15 = phi i32 [ %7, %6 ], [ %13, %11 ]
store i32 %15, i32* %1
br label %16
16: ; preds = %14, %8
%17 = phi i32 [ 1, %8 ], [ 0, %14 ]
ret i32 %17
}