#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 atoi(char *);
int snprintf(char *, int, char *, int);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int str2int(char *a, int lowerlimit, int upperlimit, int x, int *e) {
  char b[strlen(a) + 1];
  int y = atoi(a), n = snprintf(b, strlen(a) + 1, "%d", y);
  e[0] =
      n != strlen(b) || strcmp(a, b) != 0 || y < lowerlimit || y > upperlimit;
  if (e[0])
    e[1]++;
  else
    x = y;
  return x;
}


x86 assembly (clang, -O0):
<str2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
mov    -0x34(%rbp),%ecx
lea    0xe50(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
call   1030 <strlen@plt>
mov    -0x40(%rbp),%ecx
mov    %eax,%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0x39(%rbp)
jne    1215 <str2int+0xd5>
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%rdi
call   1050 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x39(%rbp)
jne    1215 <str2int+0xd5>
mov    -0x34(%rbp),%ecx
mov    $0x1,%al
cmp    -0xc(%rbp),%ecx
mov    %al,-0x39(%rbp)
jl     1215 <str2int+0xd5>
mov    -0x34(%rbp),%eax
cmp    -0x10(%rbp),%eax
setg   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
je     1242 <str2int+0x102>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    1248 <str2int+0x108>
mov    -0x34(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2int>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r13
mov    %ecx,-0x34(%rbp)
mov    %edx,-0x30(%rbp)
mov    %esi,-0x2c(%rbp)
mov    %rdi,%r14
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %r14,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%esi
lea    0xe6b(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%ecx
call   1040 <snprintf@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    %eax,%r12d
jne    11dd <str2int+0x9d>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
setne  %al
cmp    -0x2c(%rbp),%ebx
setl   %cl
cmp    -0x30(%rbp),%ebx
setg   %dl
or     %cl,%dl
or     %al,%dl
movzbl %dl,%eax
mov    %eax,0x0(%r13)
cmp    $0x1,%al
je     11e5 <str2int+0xa5>
jmp    11ed <str2int+0xad>
movl   $0x1,0x0(%r13)
addl   $0x1,0x4(%r13)
mov    -0x34(%rbp),%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @str2int(i8* %0, i32 %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32* %4, i32** %10
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 1
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %11
%20 = alloca i8, i64 %18
store i64 %18, i64* %12
%21 = load i8*, i8** %6
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %13
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %24, 1
%26 = load i32, i32* %13
%27 = call i32 @snprintf(i8* %20, i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %26)
store i32 %27, i32* %14
%28 = load i32, i32* %14
%29 = call i32 @strlen(i8* %20)
%30 = icmp ne i32 %28, %29
br i1 %30, label %43, label %31
31: ; preds = %5
%32 = load i8*, i8** %6
%33 = call i64 @strcmp(i8* %32, i8* %20)
%34 = icmp ne i64 %33, 0
br i1 %34, label %43, label %35
35: ; preds = %31
%36 = load i32, i32* %13
%37 = load i32, i32* %7
%38 = icmp slt i32 %36, %37
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i32, i32* %13
%41 = load i32, i32* %8
%42 = icmp sgt i32 %40, %41
br label %43
43: ; preds = %39, %35, %31, %5
%44 = phi i1 [ true, %35 ], [ true, %31 ], [ true, %5 ], [ %42, %39 ]
%45 = zext i1 %44 to i32
%46 = load i32*, i32** %10
%47 = getelementptr inbounds i32, i32* %46, i64 0
store i32 %45, i32* %47
%48 = load i32*, i32** %10
%49 = getelementptr inbounds i32, i32* %48, i64 0
%50 = load i32, i32* %49
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %43
%53 = load i32*, i32** %10
%54 = getelementptr inbounds i32, i32* %53, i64 1
%55 = load i32, i32* %54
%56 = add nsw i32 %55, 1
store i32 %56, i32* %54
br label %59
57: ; preds = %43
%58 = load i32, i32* %13
store i32 %58, i32* %9
br label %59
59: ; preds = %57, %52
%60 = load i32, i32* %9
%61 = load i8*, i8** %11
ret i32 %60
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @str2int(i8* %0, i32 %1, i32 %2, i32 %3, i32* nocapture %4) {
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, 1
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = tail call i32 @atoi(i8* %0)
%11 = tail call i32 @strlen(i8* %0)
%12 = add nsw i32 %11, 1
%13 = call i32 @snprintf(i8* %9, i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%14 = call i32 @strlen(i8* %9)
%15 = icmp eq i32 %13, %14
br i1 %15, label %17, label %16
16: ; preds = %5
store i32 1, i32* %4
br label %25
17: ; preds = %5
%18 = call i64 @strcmp(i8* %0, i8* %9)
%19 = icmp ne i64 %18, 0
%20 = icmp slt i32 %10, %1
%21 = select i1 %19, i1 true, i1 %20
%22 = icmp sgt i32 %10, %2
%23 = select i1 %21, i1 true, i1 %22
%24 = zext i1 %23 to i32
store i32 %24, i32* %4
br i1 %23, label %25, label %29
25: ; preds = %16, %17
%26 = getelementptr inbounds i32, i32* %4, i64 1
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
br label %29
29: ; preds = %17, %25
%30 = phi i32 [ %3, %25 ], [ %10, %17 ]
ret i32 %30
}