#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);
  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)
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    119c <getInt+0x4c>
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    11c8 <getInt+0x78>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e5 <getInt+0x95>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11df <getInt+0x8f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e5 <getInt+0x95>
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   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
mov    $0x6,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1040 <strncpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cmp    $0x6,%eax
jl     1190 <getInt+0x40>
movb   $0x0,0x5(%r12)
mov    %r12,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1030 <free@plt>
cmp    %ebx,%ebp
cmovle %ebp,%ebx
cmp    %r14d,%ebp
cmovl  %r14d,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
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** %9
%12 = load i8*, i8** %5
%13 = call i32 @strncpy(i8* %11, i8* %12, i32 5)
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = icmp sgt i32 %15, 5
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i8*, i8** %9
%19 = getelementptr inbounds i8, i8* %18, i64 5
store i8 0, i8* %19
br label %20
20: ; preds = %17, %3
%21 = load i8*, i8** %9
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %8
%23 = load i8*, i8** %9
%24 = call i32 @free(i8* %23)
%25 = load i32, i32* %8
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = load i32, i32* %6
store i32 %29, i32* %4
br label %38
30: ; preds = %20
%31 = load i32, i32* %8
%32 = load i32, i32* %7
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = load i32, i32* %7
store i32 %35, i32* %4
br label %38
36: ; preds = %30
%37 = load i32, i32* %8
store i32 %37, i32* %4
br label %38
38: ; preds = %36, %34, %28
%39 = load i32, i32* %4
ret i32 %39
}

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