#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;
};

/* Variables and functions */
int atoi(char const *);
struct passwd *getpwnam(char const *);
int /*<<< orphan*/ isdigit(char const);
int strlen(char const *);
int touid(const char *string) {
  int i, len = strlen(string);
  for (i = 0; i < len; i++) {
    if (!isdigit(string[i])) {
      struct passwd *p = getpwnam(string);
      if (p == NULL)
        return -1;
      return p->pw_uid;
    }
  }
  return atoi(string);
}


x86 assembly (clang, -O0):
<touid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ca <touid+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11b7 <touid+0x77>
mov    -0x10(%rbp),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <touid+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <touid+0x96>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <touid+0x96>
jmp    11bc <touid+0x7c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115f <touid+0x1f>
mov    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<touid>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
jle    1177 <touid+0x37>
mov    %eax,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1184 <touid+0x44>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <touid+0x20>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <atoi@plt>
mov    %r14,%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
je     1195 <touid+0x55>
mov    (%rax),%eax
jmp    119a <touid+0x5a>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.passwd = type { i32 }
define i32 @touid(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %21
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %8
6: ; preds = %8
%7 = icmp eq i64 %14, %5
br i1 %7, label %21, label %8
8: ; preds = %4, %6
%9 = phi i64 [ 0, %4 ], [ %14, %6 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @isdigit(i8 signext %11)
%13 = icmp eq i32 %12, 0
%14 = add nuw nsw i64 %9, 1
br i1 %13, label %15, label %6
15: ; preds = %8
%16 = tail call %struct.passwd* @getpwnam(i8* %0)
%17 = icmp eq %struct.passwd* %16, null
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 0
%20 = load i32, i32* %19
br label %23
21: ; preds = %6, %1
%22 = tail call i32 @atoi(i8* %0)
br label %23
23: ; preds = %18, %15, %21
%24 = phi i32 [ %22, %21 ], [ %20, %18 ], [ -1, %15 ]
ret i32 %24
}