#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 */

/* Variables and functions */
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ isdigit(int);
int parse_uidgid(const char *str) {
  int id = 0;
  int c;
  if ((c = *str) == '-')
    error(1, 0, "uid/gid %s can't be negative", str);
  while ((c = *str++)) {
    if (!isdigit(c))
      error(1, 0, "invalid character '%c' in uid/gid '%s", c, str);
    id *= 10;
    id += c - '0';
  }
  return id;
}


x86 assembly (clang, -O0):
<parse_uidgid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x10(%rbp)
cmp    $0x2d,%eax
jne    115f <parse_uidgid+0x3f>
mov    -0x8(%rbp),%rcx
mov    $0x1,%edi
xor    %esi,%esi
lea    0xea8(%rip),%rdx
mov    $0x0,%al
call   1040 <error@plt>
jmp    1164 <parse_uidgid+0x44>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     11c7 <parse_uidgid+0xa7>
mov    -0x10(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11af <parse_uidgid+0x8f>
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%r8
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe75(%rip),%rdx
mov    $0x0,%al
call   1040 <error@plt>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x30,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1164 <parse_uidgid+0x44>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_uidgid>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%al
cmp    $0x2d,%al
jne    113b <parse_uidgid+0x2b>
lea    0xed8(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <error@plt>
mov    (%rbx),%al
test   %al,%al
je     1186 <parse_uidgid+0x76>
add    $0x1,%rbx
lea    0xed3(%rip),%r14
xor    %r15d,%r15d
jmp    1163 <parse_uidgid+0x53>
nop
lea    (%r15,%r15,4),%eax
lea    (%r12,%rax,2),%r15d
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1189 <parse_uidgid+0x79>
movsbl %al,%ecx
lea    -0x30(%rcx),%r12d
cmp    $0xa,%r12d
jb     1150 <parse_uidgid+0x40>
mov    $0x1,%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %rbx,%r8
xor    %eax,%eax
call   1030 <error@plt>
jmp    1150 <parse_uidgid+0x40>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"uid/gid %s can't be negative\00"
@.str.1 = [38 x i8] c"invalid character '%c' in uid/gid '%s\00"
define i32 @parse_uidgid(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
store i32 %7, i32* %4
%8 = icmp eq i32 %7, 45
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %9, %1
br label %13
13: ; preds = %27, %12
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %2
%16 = load i8, i8* %14
%17 = sext i8 %16 to i32
store i32 %17, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %34
19: ; preds = %13
%20 = load i32, i32* %4
%21 = call i32 @isdigit(i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = load i32, i32* %4
%25 = load i8*, i8** %2
%26 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %25)
br label %27
27: ; preds = %23, %19
%28 = load i32, i32* %3
%29 = mul nsw i32 %28, 10
store i32 %29, i32* %3
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 48
%32 = load i32, i32* %3
%33 = add nsw i32 %32, %31
store i32 %33, i32* %3
br label %13
34: ; preds = %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [29 x i8] c"uid/gid %s can't be negative\00"
@.str.1 = [38 x i8] c"invalid character '%c' in uid/gid '%s\00"
define i32 @parse_uidgid(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 45
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = load i8, i8* %0
br label %7
7: ; preds = %4, %1
%8 = phi i8 [ %6, %4 ], [ %2, %1 ]
%9 = icmp eq i8 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %7, %20
%11 = phi i8 [ %23, %20 ], [ %8, %7 ]
%12 = phi i8* [ %14, %20 ], [ %0, %7 ]
%13 = phi i32 [ %22, %20 ], [ 0, %7 ]
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = sext i8 %11 to i32
%16 = add nsw i32 %15, -48
%17 = icmp ult i32 %16, 10
br i1 %17, label %20, label %18
18: ; preds = %10
%19 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %14)
br label %20
20: ; preds = %18, %10
%21 = mul nsw i32 %13, 10
%22 = add nsw i32 %16, %21
%23 = load i8, i8* %14
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %10
25: ; preds = %20, %7
%26 = phi i32 [ 0, %7 ], [ %22, %20 ]
ret i32 %26
}