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


x86 assembly (clang, -O0):
<read_param_float>:
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   $0x0,-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     1299 <read_param_float+0x119>
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    1294 <read_param_float+0x114>
cmpl   $0x0,-0x2c(%rbp)
jne    1265 <read_param_float+0xe5>
mov    -0x18(%rbp),%rdx
lea    -0xb0(%rbp),%rdi
lea    0xdd4(%rip),%rsi
call   10a0 <sscanf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1259 <read_param_float+0xd9>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdb5(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movl   $0x1,-0x2c(%rbp)
jmp    128f <read_param_float+0x10f>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
movl   $0x2,-0x30(%rbp)
jmp    1294 <read_param_float+0x114>
jmp    11bf <read_param_float+0x3f>
cmpl   $0x0,-0x2c(%rbp)
jne    12aa <read_param_float+0x12a>
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_float>:
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     1280 <read_param_float+0xf0>
lea    0x10(%rsp),%rbx
xor    %r13d,%r13d
xor    %r14d,%r14d
jmp    1222 <read_param_float+0x92>
nopl   0x0(%rax,%rax,1)
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     127b <read_param_float+0xeb>
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_float+0x7d>
test   %r14d,%r14d
jne    11e0 <read_param_float+0x50>
mov    %rbx,%rdi
lea    0xdb6(%rip),%rsi
mov    %r15,%rdx
call   10b0 <sscanf@plt>
mov    $0x1,%r14d
cmpl   $0x0,0xc(%rsp)
je     120d <read_param_float+0x7d>
movss  (%r15),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd98(%rip),%rdi
mov    %rbp,%rsi
mov    $0x1,%al
call   1060 <printf@plt>
jmp    120d <read_param_float+0x7d>
test   %r14d,%r14d
jne    1286 <read_param_float+0xf6>
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 %f\00"
@.str.1 = [9 x i8] c"%s = %f\0A\00"
@.str.2 = [23 x i8] c"found a second label!\0A\00"
@stdout = global i32 0
define i32 @read_param_float(i32* %0, i8* %1, float* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca float*
%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 float* %2, float** %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 0, i32* %12
%15 = load i32*, i32** %5
%16 = call i32 @rewind(i32* %15)
br label %17
17: ; preds = %48, %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 %49
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 %48, label %27
27: ; preds = %21
%28 = load i32, i32* %11
%29 = icmp ne i32 %28, 0
br i1 %29, label %42, label %30
30: ; preds = %27
%31 = load float*, float** %7
%32 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float* %31)
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = load float*, float** %7
%38 = load float, float* %37
%39 = fpext float %38 to double
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %36, double %39)
br label %41
41: ; preds = %35, %30
store i32 1, i32* %11
br label %47
42: ; preds = %27
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* @stdout
%45 = call i32 @fflush(i32 %44)
%46 = call i32 (...) @getchar()
store i32 2, i32* %12
br label %47
47: ; preds = %42, %41
br label %48
48: ; preds = %47, %21
br label %17
49: ; preds = %17
%50 = load i32, i32* %11
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %49
store i32 1, i32* %12
br label %53
53: ; preds = %52, %49
%54 = load i32, i32* %12
%55 = load i8*, i8** %10
ret i32 %54
}

LLVM IR (-O2):
@.str = [7 x i8] c"%*s %f\00"
@.str.1 = [9 x i8] c"%s = %f\0A\00"
@stdout = global i32 0
@str = [22 x i8] c"found a second label!\00"
define i32 @read_param_float(i32* nocapture %0, i8* %1, float* %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 %38, label %10
10: ; preds = %4
%11 = icmp eq i32 %3, 0
br label %12
12: ; preds = %10, %31
%13 = phi i32 [ 0, %10 ], [ %33, %31 ]
%14 = phi i32 [ 0, %10 ], [ %32, %31 ]
%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 %31
18: ; preds = %12
%19 = icmp eq i32 %14, 0
br i1 %19, label %20, label %26
20: ; preds = %18
%21 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float* %2)
br i1 %11, label %31, label %22
22: ; preds = %20
%23 = load float, float* %2
%24 = fpext float %23 to double
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %1, double %24)
br label %31
26: ; preds = %18
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%28 = load i32, i32* @stdout
%29 = call i32 @fflush(i32 %28)
%30 = call i32 (...) @getchar()
br label %31
31: ; preds = %20, %22, %26, %12
%32 = phi i32 [ %14, %12 ], [ 1, %26 ], [ 1, %22 ], [ 1, %20 ]
%33 = phi i32 [ %13, %12 ], [ 2, %26 ], [ %13, %22 ], [ %13, %20 ]
%34 = call i32* @fgets(i8* %6, i32 128, i32* %0)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %12
36: ; preds = %31
%37 = icmp eq i32 %32, 0
br i1 %37, label %38, label %39
38: ; preds = %4, %36
br label %39
39: ; preds = %36, %38
%40 = phi i32 [ 1, %38 ], [ %33, %36 ]
ret i32 %40
}