#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 sscanf(char const *, char *, int *);
int arg_to_int(const char *arg, int min, int max, int defalt) {
  int i = defalt;
  int rv;
  if (arg) {
    rv = sscanf(arg, "%d", &i);
    if (rv == 1) {
      if (i < min || max < i)
        i = defalt;
    } else
      i = defalt;
  }
  return i;
}


x86 assembly (clang, -O0):
<arg_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1185 <arg_to_int+0x75>
mov    -0x8(%rbp),%rdi
lea    0xebf(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    117a <arg_to_int+0x6a>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     116f <arg_to_int+0x5f>
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1175 <arg_to_int+0x65>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1180 <arg_to_int+0x70>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1185 <arg_to_int+0x75>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_to_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebx
mov    %ecx,0xc(%rsp)
test   %rdi,%rdi
je     114f <arg_to_int+0x3f>
mov    %edx,%ebp
mov    %esi,%r14d
lea    0xed1(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    114f <arg_to_int+0x3f>
mov    0xc(%rsp),%eax
cmp    %ebp,%eax
mov    %eax,%ecx
cmovg  %ebx,%ecx
cmp    %r14d,%eax
cmovge %ecx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @arg_to_int(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
store i32 %11, i32* %9
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %33
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
store i32 %16, i32* %10
%17 = load i32, i32* %10
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = load i32, i32* %9
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = load i32, i32* %7
%25 = load i32, i32* %9
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23, %19
%28 = load i32, i32* %8
store i32 %28, i32* %9
br label %29
29: ; preds = %27, %23
br label %32
30: ; preds = %14
%31 = load i32, i32* %8
store i32 %31, i32* %9
br label %32
32: ; preds = %30, %29
br label %33
33: ; preds = %32, %4
%34 = load i32, i32* %9
ret i32 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @arg_to_int(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 %3, i32* %5
%7 = icmp eq i8* %0, null
br i1 %7, label %17, label %8
8: ; preds = %4
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, %1
%14 = icmp sgt i32 %12, %2
%15 = or i1 %13, %14
%16 = select i1 %15, i32 %3, i32 %12
br label %17
17: ; preds = %11, %8, %4
%18 = phi i32 [ %3, %4 ], [ %16, %11 ], [ %3, %8 ]
ret i32 %18
}