#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 */
long strtol(char const *, char **, int);
int get_percent_arg(const char *arg, unsigned long *value) {
  long t;
  char *suffix;
  t = strtol(arg, &suffix, 10);
  if (*suffix == '%') {
    suffix++;
  }
  if (t < 0 || t > 100 || *suffix != 0) {
    return 1;
  }
  *value = (unsigned long)t;
  return 0;
}


x86 assembly (clang, -O0):
<get_percent_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1152 <get_percent_arg+0x42>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     1178 <get_percent_arg+0x68>
cmpq   $0x64,-0x20(%rbp)
jg     1178 <get_percent_arg+0x68>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1184 <get_percent_arg+0x74>
movl   $0x1,-0x4(%rbp)
jmp    1196 <get_percent_arg+0x86>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_percent_arg>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    $0x1,%eax
cmp    $0x64,%rcx
ja     114e <get_percent_arg+0x3e>
mov    0x8(%rsp),%rdx
xor    %esi,%esi
cmpb   $0x25,(%rdx)
sete   %sil
cmpb   $0x0,(%rdx,%rsi,1)
jne    114e <get_percent_arg+0x3e>
mov    %rcx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @get_percent_arg(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i8*, i8** %3
%7 = icmp ugt i64 %5, 100
br i1 %7, label %16, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 37
%11 = zext i1 %10 to i64
%12 = getelementptr i8, i8* %6, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %8
store i64 %5, i64* %1
br label %16
16: ; preds = %2, %8, %15
%17 = phi i32 [ 0, %15 ], [ 1, %8 ], [ 1, %2 ]
ret i32 %17
}