#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 libc_strlen(char *);
unsigned int libc_stoui(char *s) {
  int i = 0, n = 0;
  for (n = 0, i = 0; libc_strlen(s) > i; i++) {
    if (s[i] == '-') {
      i++;
    }
    n = 10 * n + (s[i] - '0');
  }
  return n;
}


x86 assembly (clang, -O0):
<libc_stoui>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <libc_strlen@plt>
cmp    -0xc(%rbp),%eax
jle    118e <libc_stoui+0x7e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    1168 <libc_stoui+0x58>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
imul   $0xa,-0x10(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1138 <libc_stoui+0x28>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libc_stoui>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <libc_strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
jle    1163 <libc_stoui+0x53>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ebp,%rax
xor    %ecx,%ecx
cmpb   $0x2d,(%r14,%rax,1)
sete   %cl
lea    (%rax,%rcx,1),%edx
lea    (%rbx,%rbx,4),%esi
movslq %edx,%rdx
movsbl (%r14,%rdx,1),%edx
lea    (%rdx,%rsi,2),%ebx
add    $0xffffffd0,%ebx
lea    (%rax,%rcx,1),%ebp
add    $0x1,%ebp
mov    %r14,%rdi
call   1030 <libc_strlen@plt>
cmp    %ebp,%eax
jg     1130 <libc_stoui+0x20>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @libc_stoui(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %32, %1
%6 = load i8*, i8** %2
%7 = call i32 @libc_strlen(i8* %6)
%8 = load i32, i32* %3
%9 = icmp sgt i32 %7, %8
br i1 %9, label %10, label %35
10: ; preds = %5
%11 = load i8*, i8** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 45
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %21
21: ; preds = %18, %10
%22 = load i32, i32* %4
%23 = mul nsw i32 10, %22
%24 = load i8*, i8** %2
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = sub nsw i32 %29, 48
%31 = add nsw i32 %23, %30
store i32 %31, i32* %4
br label %32
32: ; preds = %21
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %5
35: ; preds = %5
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @libc_stoui(i8* %0) {
%2 = tail call i32 @libc_strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %23
4: ; preds = %1, %4
%5 = phi i32 [ %19, %4 ], [ 0, %1 ]
%6 = phi i32 [ %20, %4 ], [ 0, %1 ]
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 45
%11 = zext i1 %10 to i32
%12 = add nsw i32 %6, %11
%13 = mul nsw i32 %5, 10
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = add i32 %13, -48
%19 = add i32 %18, %17
%20 = add nsw i32 %12, 1
%21 = tail call i32 @libc_strlen(i8* %0)
%22 = icmp sgt i32 %21, %20
br i1 %22, label %4, label %23
23: ; preds = %4, %1
%24 = phi i32 [ 0, %1 ], [ %19, %4 ]
ret i32 %24
}