#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 EOF;
int /*<<< orphan*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ stderr;
double readReal(FILE *fp) {
  int result;
  double x;
  result = fscanf(fp, " %lf", &x);
  if (result == EOF) {
    return 0.0;
  }
  if (result == 0) {
    fprintf(stderr, "SCAN ERROR: attempt to read a real number failed\n");
    fprintf(stderr, "offending character was <%c>\n", fgetc(fp));
    exit(2);
  }
  return x;
}


x86 assembly (clang, -O0):
<readReal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <fscanf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
jne    1182 <readReal+0x42>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11df <readReal+0x9f>
cmpl   $0x0,-0x14(%rbp)
jne    11d5 <readReal+0x95>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readReal>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeb3(%rip),%rsi
mov    %rsp,%rdx
call   1030 <fscanf@plt>
mov    0x2e8c(%rip),%rcx
xorps  %xmm0,%xmm0
cmp    (%rcx),%eax
je     116c <readReal+0x2c>
test   %eax,%eax
je     1173 <readReal+0x33>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e5e(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe81(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%ebp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
lea    0xe9a(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c" %lf\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [50 x i8] c"SCAN ERROR: attempt to read a real number failed\0A\00"
@.str.2 = [30 x i8] c"offending character was <%c>\0A\00"
define double @readReal(i32* %0) {
%2 = alloca double
%3 = alloca i32*
%4 = alloca i32
%5 = alloca double
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double* %5)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %1
store double 0.000000e+00, double* %2
br label %25
12: ; preds = %1
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = load i32*, i32** %3
%20 = call i32 @fgetc(i32* %19)
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 @exit(i32 2)
unreachable
23: ; preds = %12
%24 = load double, double* %5
store double %24, double* %2
br label %25
25: ; preds = %23, %11
%26 = load double, double* %2
ret double %26
}

LLVM IR (-O2):
@.str = [5 x i8] c" %lf\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [50 x i8] c"SCAN ERROR: attempt to read a real number failed\0A\00"
@.str.2 = [30 x i8] c"offending character was <%c>\0A\00"
define double @readReal(i32* nocapture %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
%4 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double* %2)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %18, label %7
7: ; preds = %1
%8 = icmp eq i32 %4, 0
br i1 %8, label %9, label %16
9: ; preds = %7
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = call i32 @fgetc(i32* %0)
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 2)
unreachable
16: ; preds = %7
%17 = load double, double* %2
br label %18
18: ; preds = %1, %16
%19 = phi double [ %17, %16 ], [ 0.000000e+00, %1 ]
ret double %19
}