#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, char const *, ...);
int read_param_int(int /*<<< orphan*/ *, char const *, unsigned int *,
                   int /*<<< orphan*/);
int readordef_param_int(const char *fn, const char *label, unsigned int *val,
                        const int defaultvalue, const int verbose) {
  int rerr = 1;
  int errcode = 3;
  FILE *fp;
  if ((fp = fopen(fn, "r")) != NULL) {
    rerr = read_param_int(fp, label, val, 0);
    switch (rerr) {
    case 2:
      printf("Multiple instances of %s specified. Check config file\n", label);
      getchar();
      exit(0);
    case 0:
      if (verbose)
        printf("Setting %s to %d\n", label, *val);
      errcode = 0;
      break;
    default:
      if (defaultvalue < 0) {
        errcode = 1;
      } else {
        *val = defaultvalue;
        errcode = 0;
        if (verbose)
          printf("%s not specified;\nSetting %s to %d\n", label, label, *val);
      }
      break;
    }
    fclose(fp);
  }
  if (verbose)
    printf("%s = %d\n", label, *val);
  return errcode;
}


x86 assembly (clang, -O0):
<readordef_param_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x3,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     128e <readordef_param_int+0x12e>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1050 <read_param_int@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     1201 <readordef_param_int+0xa1>
jmp    11d0 <readordef_param_int+0x70>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
jne    122f <readordef_param_int+0xcf>
jmp    11e1 <readordef_param_int+0x81>
mov    -0x10(%rbp),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
xor    %edi,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
je     1223 <readordef_param_int+0xc3>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x28(%rbp)
jmp    1285 <readordef_param_int+0x125>
cmpl   $0x0,-0x1c(%rbp)
jge    1245 <readordef_param_int+0xe5>
movl   $0x1,-0x28(%rbp)
jmp    1280 <readordef_param_int+0x120>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     127b <readordef_param_int+0x11b>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1280 <readordef_param_int+0x120>
jmp    1285 <readordef_param_int+0x125>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x20(%rbp)
je     12b0 <readordef_param_int+0x150>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readordef_param_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %rdx,%r12
mov    %rsi,%r14
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d3 <readordef_param_int+0x73>
mov    %rax,%rbp
xor    %ebx,%ebx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1050 <read_param_int@plt>
test   %eax,%eax
je     11df <readordef_param_int+0x7f>
cmp    $0x2,%eax
je     1239 <readordef_param_int+0xd9>
test   %r13d,%r13d
js     11fd <readordef_param_int+0x9d>
mov    %r13d,(%r12)
test   %r15d,%r15d
je     1204 <readordef_param_int+0xa4>
lea    0xe7a(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
mov    %r14,%rdx
mov    %r13d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1206 <readordef_param_int+0xa6>
mov    $0x3,%ebx
test   %r15d,%r15d
jne    1213 <readordef_param_int+0xb3>
jmp    1228 <readordef_param_int+0xc8>
test   %r15d,%r15d
je     1206 <readordef_param_int+0xa6>
mov    (%r12),%edx
lea    0xe5c(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1206 <readordef_param_int+0xa6>
mov    $0x1,%ebx
jmp    1206 <readordef_param_int+0xa6>
xor    %ebx,%ebx
mov    %rbp,%rdi
call   1030 <fclose@plt>
test   %r15d,%r15d
je     1228 <readordef_param_int+0xc8>
mov    (%r12),%edx
lea    0xe3f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc2(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [55 x i8] c"Multiple instances of %s specified. Check config file\0A\00"
@.str.2 = [18 x i8] c"Setting %s to %d\0A\00"
@.str.3 = [36 x i8] c"%s not specified;\0ASetting %s to %d\0A\00"
@.str.4 = [9 x i8] c"%s = %d\0A\00"
define i32 @readordef_param_int(i8* %0, i8* %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 1, i32* %11
store i32 3, i32* %12
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %13
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %57
17: ; preds = %5
%18 = load i32*, i32** %13
%19 = load i8*, i8** %7
%20 = load i32*, i32** %8
%21 = call i32 @read_param_int(i32* %18, i8* %19, i32* %20, i32 0)
store i32 %21, i32* %11
%22 = load i32, i32* %11
switch i32 %22, label %37 [
i32 2, label %23
i32 0, label %28
]
23: ; preds = %17
%24 = load i8*, i8** %7
%25 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = call i32 (...) @getchar()
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %17
%29 = load i32, i32* %10
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = load i32*, i32** %8
%34 = load i32, i32* %33
%35 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %32, i32 %34)
br label %36
36: ; preds = %31, %28
store i32 0, i32* %12
br label %54
37: ; preds = %17
%38 = load i32, i32* %9
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 1, i32* %12
br label %53
41: ; preds = %37
%42 = load i32, i32* %9
%43 = load i32*, i32** %8
store i32 %42, i32* %43
store i32 0, i32* %12
%44 = load i32, i32* %10
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %41
%47 = load i8*, i8** %7
%48 = load i8*, i8** %7
%49 = load i32*, i32** %8
%50 = load i32, i32* %49
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %47, i8* %48, i32 %50)
br label %52
52: ; preds = %46, %41
br label %53
53: ; preds = %52, %40
br label %54
54: ; preds = %53, %36
%55 = load i32*, i32** %13
%56 = call i32 @fclose(i32* %55)
br label %57
57: ; preds = %54, %5
%58 = load i32, i32* %10
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %57
%61 = load i8*, i8** %7
%62 = load i32*, i32** %8
%63 = load i32, i32* %62
%64 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %61, i32 %63)
br label %65
65: ; preds = %60, %57
%66 = load i32, i32* %12
ret i32 %66
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [55 x i8] c"Multiple instances of %s specified. Check config file\0A\00"
@.str.2 = [18 x i8] c"Setting %s to %d\0A\00"
@.str.3 = [36 x i8] c"%s not specified;\0ASetting %s to %d\0A\00"
@.str.4 = [9 x i8] c"%s = %d\0A\00"
define i32 @readordef_param_int(i8* nocapture %0, i8* %1, i32* %2, i32 %3, i32 %4) {
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %28, label %8
8: ; preds = %5
%9 = tail call i32 @read_param_int(i32* %6, i8* %1, i32* %2, i32 0)
switch i32 %9, label %19 [
i32 2, label %10
i32 0, label %14
]
10: ; preds = %8
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%12 = tail call i32 (...) @getchar()
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %8
%15 = icmp eq i32 %4, 0
br i1 %15, label %25, label %16
16: ; preds = %14
%17 = load i32, i32* %2
%18 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %17)
br label %25
19: ; preds = %8
%20 = icmp slt i32 %3, 0
br i1 %20, label %25, label %21
21: ; preds = %19
store i32 %3, i32* %2
%22 = icmp eq i32 %4, 0
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %1, i32 %3)
br label %25
25: ; preds = %19, %14, %16, %23, %21
%26 = phi i32 [ 0, %23 ], [ 0, %21 ], [ 0, %16 ], [ 0, %14 ], [ 1, %19 ]
%27 = tail call i32 @fclose(i32* %6)
br label %28
28: ; preds = %25, %5
%29 = phi i32 [ %26, %25 ], [ 3, %5 ]
%30 = icmp eq i32 %4, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* %2
%33 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %1, i32 %32)
br label %34
34: ; preds = %31, %28
ret i32 %29
}