#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 */
typedef int int32_t;

/* Variables and functions */
scalar_t__ EINVAL;
long long INT_MAX;
long long INT_MIN;
int /*<<< orphan*/ convFail(char *, char *, char const *, char const *);
long long convNum(char *, char const *, int, char const *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int convInt(const char *arg, int32_t flags, const char *varName) {
  register long long res = 0;
  res = convNum("convInt", arg, flags, varName);
  if (errno)
    return 0;
  if (res > INT_MAX || res < INT_MIN) {
    if (flags & 0x20) {
      errno = EINVAL;
      fprintf(stderr, "\nInteger was out of range\n");
      return 0;
    } else {
      convFail("convInt", "integer out of range", arg, varName);
    }
  }
  return (int)res;
}


x86 assembly (clang, -O0):
<convInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xea3(%rip),%rdi
call   1050 <convNum@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e5b(%rip),%rax
cmpq   $0x0,(%rax)
je     1183 <convInt+0x53>
movl   $0x0,-0x4(%rbp)
jmp    1216 <convInt+0xe6>
mov    -0x28(%rbp),%rax
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%rax
jg     11ab <convInt+0x7b>
mov    -0x28(%rbp),%rax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%rax
jge    120f <convInt+0xdf>
mov    -0x14(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     11ef <convInt+0xbf>
mov    0x2dff(%rip),%rax
mov    (%rax),%rcx
mov    0x2dfd(%rip),%rax
mov    %rcx,(%rax)
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1216 <convInt+0xe6>
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe02(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   1030 <convFail@plt>
jmp    120f <convInt+0xdf>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convInt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%r12
lea    0xeb9(%rip),%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %r14,%rcx
call   1050 <convNum@plt>
mov    %rax,%r15
mov    0x2e6a(%rip),%rax
xor    %ebp,%ebp
cmpq   $0x0,(%rax)
jne    11c3 <convInt+0x93>
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%r15
jg     117e <convInt+0x4e>
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%r15
jge    119c <convInt+0x6c>
test   $0x20,%bl
jne    11a1 <convInt+0x71>
lea    0xe76(%rip),%rdi
lea    0xe92(%rip),%rsi
mov    %r12,%rdx
mov    %r14,%rcx
call   1030 <convFail@plt>
mov    %r15d,%ebp
jmp    11c3 <convInt+0x93>
mov    0x2e18(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,(%rax)
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"convInt\00"
@errno = global i64 0
@INT_MAX = global i64 0
@INT_MIN = global i64 0
@EINVAL = global i64 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"\0AInteger was out of range\0A\00"
@.str.2 = [21 x i8] c"integer out of range\00"
define i32 @convInt(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 0, i64* %8
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = load i8*, i8** %7
%12 = call i64 @convNum(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10, i8* %11)
store i64 %12, i64* %8
%13 = load i64, i64* @errno
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 0, i32* %4
br label %40
16: ; preds = %3
%17 = load i64, i64* %8
%18 = load i64, i64* @INT_MAX
%19 = icmp sgt i64 %17, %18
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i64, i64* %8
%22 = load i64, i64* @INT_MIN
%23 = icmp slt i64 %21, %22
br i1 %23, label %24, label %37
24: ; preds = %20, %16
%25 = load i32, i32* %6
%26 = and i32 %25, 32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i64, i64* @EINVAL
store i64 %29, i64* @errno
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %40
32: ; preds = %24
%33 = load i8*, i8** %5
%34 = load i8*, i8** %7
%35 = call i32 @convFail(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %34)
br label %36
36: ; preds = %32
br label %37
37: ; preds = %36, %20
%38 = load i64, i64* %8
%39 = trunc i64 %38 to i32
store i32 %39, i32* %4
br label %40
40: ; preds = %37, %28, %15
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@.str = [8 x i8] c"convInt\00"
@errno = global i64 0
@INT_MAX = global i64 0
@INT_MIN = global i64 0
@EINVAL = global i64 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"\0AInteger was out of range\0A\00"
@.str.2 = [21 x i8] c"integer out of range\00"
define i32 @convInt(i8* %0, i32 %1, i8* %2) {
%4 = tail call i64 @convNum(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i8* %2)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %3
%8 = load i64, i64* @INT_MAX
%9 = icmp sgt i64 %4, %8
%10 = load i64, i64* @INT_MIN
%11 = icmp slt i64 %4, %10
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %13, label %22
13: ; preds = %7
%14 = and i32 %1, 32
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i64, i64* @EINVAL
store i64 %17, i64* @errno
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %24
20: ; preds = %13
%21 = tail call i32 @convFail(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %2)
br label %22
22: ; preds = %7, %20
%23 = trunc i64 %4 to i32
br label %24
24: ; preds = %3, %22, %16
%25 = phi i32 [ 0, %16 ], [ %23, %22 ], [ 0, %3 ]
ret i32 %25
}