#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 */
float atof(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
float t4scale(char *t4file) {
  FILE *fp;
  float q;
  char *ptr, string[256];
  q = 1.0;
  if (!(fp = fopen(t4file, "r"))) {
    fprintf(stderr, "t4scale: %s read error\n", t4file);
    exit(-1);
  }
  while (fgets(string, 256, fp))
    if ((ptr = strstr(string, "scale:")))
      q = atof(ptr + 6);
  fclose(fp);
  return q;
}


x86 assembly (clang, -O0):
<t4scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movss  0xe79(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11cd <t4scale+0x5d>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe48(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    11d2 <t4scale+0x62>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1229 <t4scale+0xb9>
lea    -0x120(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1224 <t4scale+0xb4>
mov    -0x20(%rbp),%rdi
add    $0x6,%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x14(%rbp)
jmp    11d2 <t4scale+0x62>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movss  -0x14(%rbp),%xmm0
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t4scale>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%rbx
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     122a <t4scale+0xba>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
movss  0xe4f(%rip),%xmm0
test   %rax,%rax
je     1209 <t4scale+0x99>
movss  %xmm0,0xc(%rsp)
lea    0xe5b(%rip),%r14
lea    0x10(%rsp),%rbx
jmp    11e5 <t4scale+0x75>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     120f <t4scale+0x9f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11d0 <t4scale+0x60>
add    $0x6,%rax
mov    %rax,%rdi
call   1030 <atof@plt>
movss  %xmm0,0xc(%rsp)
jmp    11d0 <t4scale+0x60>
movss  %xmm0,0xc(%rsp)
mov    %r15,%rdi
call   1040 <fclose@plt>
movss  0xc(%rsp),%xmm0
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"t4scale: %s read error\0A\00"
@.str.2 = [7 x i8] c"scale:\00"
define float @t4scale(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca float
%5 = alloca i8*
%6 = alloca [256 x i8]
store i8* %0, i8** %2
store float 1.000000e+00, float* %4
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %1
br label %16
16: ; preds = %29, %15
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %3
%19 = call i64 @fgets(i8* %17, i32 256, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%23 = call i8* @strstr(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %23, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 6
%28 = call float @atof(i8* %27)
store float %28, float* %4
br label %29
29: ; preds = %25, %21
br label %16
30: ; preds = %16
%31 = load i32*, i32** %3
%32 = call i32 @fclose(i32* %31)
%33 = load float, float* %4
ret float %33
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"t4scale: %s read error\0A\00"
@.str.2 = [7 x i8] c"scale:\00"
define float @t4scale(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = call i64 @fgets(i8* %3, i32 256, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %24, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %6, %20
%14 = phi float [ %21, %20 ], [ 1.000000e+00, %6 ]
%15 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %15, i64 6
%19 = call float @atof(i8* %18)
br label %20
20: ; preds = %17, %13
%21 = phi float [ %19, %17 ], [ %14, %13 ]
%22 = call i64 @fgets(i8* %3, i32 256, i32* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %13
24: ; preds = %20, %6
%25 = phi float [ 1.000000e+00, %6 ], [ %21, %20 ]
%26 = call i32 @fclose(i32* %4)
ret float %25
}