#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int /*<<< orphan*/);
int read_param_int(FILE *fp, const char *label, unsigned int *val,
                   int verbose) {
  const int maxl = 128;
  char line[maxl];
  int found = 0;
  int err = 1;
  rewind(fp);
  while ((fgets(line, maxl, fp)) != NULL) {
    if (!strncmp(label, line, strlen(label))) {
      if (!found) {
        sscanf(line, "%*s %d", val);
        if (verbose)
          printf("%s = %d\n", label, *val);
        found = 1;
        err = 0;
      } else {
        printf("found a second label!\n");
        fflush(stdout);
        getchar();
        err = 2;
      }
    }
  }
  if (!found)
    err = 1;
  return err;
}


x86 assembly (clang, -O0):
<read_param_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x80,-0x20(%rbp)
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x8(%rbp),%rdx
lea    -0xb0(%rbp),%rdi
mov    $0x80,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     129a <read_param_int+0x11a>
mov    -0x10(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%edx
lea    -0xb0(%rbp),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1295 <read_param_int+0x115>
cmpl   $0x0,-0x2c(%rbp)
jne    1266 <read_param_int+0xe6>
mov    -0x18(%rbp),%rdx
lea    -0xb0(%rbp),%rdi
lea    0xdd4(%rip),%rsi
call   10a0 <sscanf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1253 <read_param_int+0xd3>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
jmp    1290 <read_param_int+0x110>
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
movl   $0x2,-0x30(%rbp)
jmp    1295 <read_param_int+0x115>
jmp    11bf <read_param_int+0x3f>
cmpl   $0x0,-0x2c(%rbp)
jne    12ab <read_param_int+0x12b>
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_param_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %ecx,0xc(%rsp)
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r12
call   1070 <rewind@plt>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1282 <read_param_int+0xf2>
mov    $0x1,%r13d
lea    0x10(%rsp),%rbx
xor    %r14d,%r14d
jmp    1222 <read_param_int+0x92>
xchg   %ax,%ax
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    $0x2,%r13d
mov    $0x1,%r14d
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     127d <read_param_int+0xed>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    120d <read_param_int+0x7d>
test   %r14d,%r14d
jne    11e0 <read_param_int+0x50>
mov    %rbx,%rdi
lea    0xdb6(%rip),%rsi
mov    %r15,%rdx
call   10b0 <sscanf@plt>
mov    $0x1,%r14d
cmpl   $0x0,0xc(%rsp)
je     1278 <read_param_int+0xe8>
mov    (%r15),%edx
xor    %r13d,%r13d
lea    0xd9b(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    120d <read_param_int+0x7d>
xor    %r13d,%r13d
jmp    120d <read_param_int+0x7d>
test   %r14d,%r14d
jne    1288 <read_param_int+0xf8>
mov    $0x1,%r13d
mov    %r13d,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%*s %d\00"
@.str.1 = [9 x i8] c"%s = %d\0A\00"
@.str.2 = [23 x i8] c"found a second label!\0A\00"
@stdout = global i32 0
define i32 @read_param_int(i32* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i32 128, i32* %9
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %10
%14 = alloca i8, i64 128
store i32 0, i32* %11
store i32 1, i32* %12
%15 = load i32*, i32** %5
%16 = call i32 @rewind(i32* %15)
br label %17
17: ; preds = %47, %4
%18 = load i32*, i32** %5
%19 = call i32* @fgets(i8* %14, i32 128, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %48
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @strncmp(i8* %22, i8* %14, i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %47, label %27
27: ; preds = %21
%28 = load i32, i32* %11
%29 = icmp ne i32 %28, 0
br i1 %29, label %41, label %30
30: ; preds = %27
%31 = load i32*, i32** %7
%32 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %31)
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = load i32*, i32** %7
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %36, i32 %38)
br label %40
40: ; preds = %35, %30
store i32 1, i32* %11
store i32 0, i32* %12
br label %46
41: ; preds = %27
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* @stdout
%44 = call i32 @fflush(i32 %43)
%45 = call i32 (...) @getchar()
store i32 2, i32* %12
br label %46
46: ; preds = %41, %40
br label %47
47: ; preds = %46, %21
br label %17
48: ; preds = %17
%49 = load i32, i32* %11
%50 = icmp ne i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %48
store i32 1, i32* %12
br label %52
52: ; preds = %51, %48
%53 = load i32, i32* %12
%54 = load i8*, i8** %10
ret i32 %53
}

LLVM IR (-O2):
@.str = [7 x i8] c"%*s %d\00"
@.str.1 = [9 x i8] c"%s = %d\0A\00"
@stdout = global i32 0
@str = [22 x i8] c"found a second label!\00"
define i32 @read_param_int(i32* nocapture %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @rewind(i32* %0)
%8 = call i32* @fgets(i8* %6, i32 128, i32* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %37, label %10
10: ; preds = %4
%11 = icmp eq i32 %3, 0
br label %12
12: ; preds = %10, %30
%13 = phi i32 [ 1, %10 ], [ %32, %30 ]
%14 = phi i32 [ 0, %10 ], [ %31, %30 ]
%15 = call i32 @strlen(i8* %1)
%16 = call i32 @strncmp(i8* %1, i8* %6, i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %12
%19 = icmp eq i32 %14, 0
br i1 %19, label %20, label %25
20: ; preds = %18
%21 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %2)
br i1 %11, label %30, label %22
22: ; preds = %20
%23 = load i32, i32* %2
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %23)
br label %30
25: ; preds = %18
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = call i32 @fflush(i32 %27)
%29 = call i32 (...) @getchar()
br label %30
30: ; preds = %20, %22, %25, %12
%31 = phi i32 [ %14, %12 ], [ 1, %25 ], [ 1, %22 ], [ 1, %20 ]
%32 = phi i32 [ %13, %12 ], [ 2, %25 ], [ 0, %22 ], [ 0, %20 ]
%33 = call i32* @fgets(i8* %6, i32 128, i32* %0)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %12
35: ; preds = %30
%36 = icmp eq i32 %31, 0
br i1 %36, label %37, label %38
37: ; preds = %4, %35
br label %38
38: ; preds = %35, %37
%39 = phi i32 [ 1, %37 ], [ %32, %35 ]
ret i32 %39
}