#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 /*<<< orphan*/ free(char *);
char *malloc(int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int getInt(char *s, int low, int high) {
  int ival;
  char *temp = malloc(6);
  if (s == NULL)
    return low;
  strncpy(temp, s, 5);
  if (strlen(s) > 5)
    *(temp + 5) = '\0';
  ival = atoi(temp);
  free(temp);
  if (ival < low)
    return low;
  if (ival > high)
    return high;
  return ival;
}


x86 assembly (clang, -O0):
<getInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    $0x6,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1186 <getInt+0x36>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fb <getInt+0xab>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x5,%edx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x5,%eax
jle    11b2 <getInt+0x62>
mov    -0x28(%rbp),%rax
movb   $0x0,0x5(%rax)
mov    -0x28(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11de <getInt+0x8e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fb <getInt+0xab>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11f5 <getInt+0xa5>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fb <getInt+0xab>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getInt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
mov    $0x6,%edi
call   1060 <malloc@plt>
test   %rbx,%rbx
je     11b4 <getInt+0x64>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x6,%eax
jl     1193 <getInt+0x43>
movb   $0x0,0x5(%rbp)
mov    %rbp,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
cmp    %r15d,%ebx
jl     11b4 <getInt+0x64>
cmp    %r14d,%ebx
cmovg  %r14d,%ebx
mov    %ebx,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getInt(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = call i8* @malloc(i32 6)
store i8* %10, i8** %9
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32, i32* %6
store i32 %14, i32* %4
br label %43
15: ; preds = %3
%16 = load i8*, i8** %9
%17 = load i8*, i8** %5
%18 = call i32 @strncpy(i8* %16, i8* %17, i32 5)
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
%21 = icmp sgt i32 %20, 5
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i8*, i8** %9
%24 = getelementptr inbounds i8, i8* %23, i64 5
store i8 0, i8* %24
br label %25
25: ; preds = %22, %15
%26 = load i8*, i8** %9
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %8
%28 = load i8*, i8** %9
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* %8
%31 = load i32, i32* %6
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = load i32, i32* %6
store i32 %34, i32* %4
br label %43
35: ; preds = %25
%36 = load i32, i32* %8
%37 = load i32, i32* %7
%38 = icmp sgt i32 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = load i32, i32* %7
store i32 %40, i32* %4
br label %43
41: ; preds = %35
%42 = load i32, i32* %8
store i32 %42, i32* %4
br label %43
43: ; preds = %41, %39, %33, %13
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
define i32 @getInt(i8* %0, i32 %1, i32 %2) {
%4 = tail call dereferenceable_or_null(6) i8* @malloc(i32 6)
%5 = icmp eq i8* %0, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = tail call i32 @strncpy(i8* %4, i8* %0, i32 5)
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp sgt i32 %8, 5
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %4, i64 5
store i8 0, i8* %11
br label %12
12: ; preds = %10, %6
%13 = tail call i32 @atoi(i8* %4)
%14 = tail call i32 @free(i8* %4)
%15 = icmp slt i32 %13, %1
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = icmp sgt i32 %13, %2
%18 = select i1 %17, i32 %2, i32 %13
br label %19
19: ; preds = %16, %12, %3
%20 = phi i32 [ %1, %3 ], [ %1, %12 ], [ %18, %16 ]
ret i32 %20
}