#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*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
double integral_1(int);
double integral_2(int);
int /*<<< orphan*/ perror(char *);
int main(void) {
  FILE *fout;
  fout = fopen("result_1", "w");
  if (fout == NULL) {
    perror("fopen() result_1");
    abort();
  }
  fprintf(fout, "%.12f", integral_1((1 << 22)));
  fclose(fout);
  fout = fopen("result_2", "w");
  if (fout == NULL) {
    perror("fopen() result_2");
    abort();
  }
  fprintf(fout, "%.12f", integral_2((1 << 22)));
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe84(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <main+0x44>
lea    0xe5a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x400000,%edi
call   1070 <integral_1@plt>
mov    -0x18(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe3b(%rip),%rdi
lea    0xe13(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1214 <main+0xa4>
lea    0xe11(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x400000,%edi
call   1050 <integral_2@plt>
mov    -0x20(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe92(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ed <main+0x7d>
mov    %rax,%rbx
mov    $0x400000,%edi
call   1070 <integral_1@plt>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe6d(%rip),%rdi
lea    0xe45(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f6 <main+0x86>
mov    %rax,%rbx
mov    $0x400000,%edi
call   1050 <integral_2@plt>
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe0e(%rip),%rdi
jmp    11fd <main+0x8d>
lea    0xe1c(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"result_1\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [17 x i8] c"fopen() result_1\00"
@.str.3 = [6 x i8] c"%.12f\00"
@.str.4 = [9 x i8] c"result_2\00"
@.str.5 = [17 x i8] c"fopen() result_2\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (...) @abort()
unreachable
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = call double @integral_1(i32 4194304)
%12 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %11)
%13 = load i32*, i32** %2
%14 = call i32 @fclose(i32* %13)
%15 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %2
%16 = load i32*, i32** %2
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %9
%19 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %9
%22 = load i32*, i32** %2
%23 = call double @integral_2(i32 4194304)
%24 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %23)
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"result_1\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [17 x i8] c"fopen() result_1\00"
@.str.3 = [6 x i8] c"%.12f\00"
@.str.4 = [9 x i8] c"result_2\00"
@.str.5 = [17 x i8] c"fopen() result_2\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 (...) @abort()
unreachable
6: ; preds = %0
%7 = tail call double @integral_1(i32 4194304)
%8 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %7)
%9 = tail call i32 @fclose(i32* %1)
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %6
%16 = tail call double @integral_2(i32 4194304)
%17 = tail call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %16)
%18 = tail call i32 @fclose(i32* %10)
ret i32 0
}