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

/* Variables and functions */
struct passwd *getpwnam(char *);
int strtol(char *, char **, int);
int user2uid(int *uid, int *gid, char *user) {
  char *tmp;
  struct passwd *pw_entry;
  if (user) {
    *uid = strtol(user, &tmp, 10);
    if ((tmp == 0) || (*tmp)) {
      pw_entry = getpwnam(user);
      if (pw_entry == 0) {
        goto error;
      }
      *uid = pw_entry->pw_uid;
      if (gid)
        *gid = pw_entry->pw_gid;
    }
    return 0;
  }
error:
  return -1;
}


x86 assembly (clang, -O0):
<user2uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c6 <user2uid+0xa6>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1174 <user2uid+0x54>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ba <user2uid+0x9a>
mov    -0x20(%rbp),%rdi
call   1030 <getpwnam@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1191 <user2uid+0x71>
jmp    11cb <user2uid+0xab>
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11b5 <user2uid+0x95>
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11ba <user2uid+0x9a>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <user2uid+0xb2>
jmp    11cb <user2uid+0xab>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<user2uid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdx,%rdx
je     117e <user2uid+0x5e>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%rsi
mov    %rdx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,(%r15)
mov    (%rsp),%rax
test   %rax,%rax
je     115b <user2uid+0x3b>
cmpb   $0x0,(%rax)
je     117c <user2uid+0x5c>
mov    %rbx,%rdi
call   1030 <getpwnam@plt>
test   %rax,%rax
je     117e <user2uid+0x5e>
mov    (%rax),%ecx
mov    %ecx,(%r15)
xor    %ebp,%ebp
test   %r14,%r14
je     117e <user2uid+0x5e>
mov    0x4(%rax),%eax
mov    %eax,(%r14)
jmp    117e <user2uid+0x5e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32, i32 }
define i32 @user2uid(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.passwd*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %43
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = call i32 @strtol(i8* %13, i8** %8, i32 10)
%15 = load i32*, i32** %5
store i32 %14, i32* %15
%16 = load i8*, i8** %8
%17 = icmp eq i8* %16, null
br i1 %17, label %23, label %18
18: ; preds = %12
%19 = load i8*, i8** %8
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %42
23: ; preds = %18, %12
%24 = load i8*, i8** %7
%25 = call %struct.passwd* @getpwnam(i8* %24)
store %struct.passwd* %25, %struct.passwd** %9
%26 = load %struct.passwd*, %struct.passwd** %9
%27 = icmp eq %struct.passwd* %26, null
br i1 %27, label %28, label %29
28: ; preds = %23
br label %44
29: ; preds = %23
%30 = load %struct.passwd*, %struct.passwd** %9
%31 = getelementptr inbounds %struct.passwd, %struct.passwd* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = load i32*, i32** %5
store i32 %32, i32* %33
%34 = load i32*, i32** %6
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %41
36: ; preds = %29
%37 = load %struct.passwd*, %struct.passwd** %9
%38 = getelementptr inbounds %struct.passwd, %struct.passwd* %37, i32 0, i32 1
%39 = load i32, i32* %38
%40 = load i32*, i32** %6
store i32 %39, i32* %40
br label %41
41: ; preds = %36, %29
br label %42
42: ; preds = %41, %18
store i32 0, i32* %4
br label %45
43: ; preds = %3
br label %44
44: ; preds = %43, %28
store i32 -1, i32* %4
br label %45
45: ; preds = %44, %42
%46 = load i32, i32* %4
ret i32 %46
}

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