#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  float sine, cosine;
  char *sineFilename, *cosineFilename;
  FILE *fd;
  sineFilename = (char *)malloc(sizeof(char) * 14);
  strcpy(sineFilename, "sineresult.txt");
  fd = fopen(sineFilename, "r");
  if (fd == NULL) {
    printf("File does not exist\n");
    exit(-1);
  }
  fscanf(fd, "%f", &sine);
  fclose(fd);
  cosineFilename = (char *)malloc(sizeof(char) * 16);
  strcpy(cosineFilename, "cosineresult.txt");
  fd = fopen(cosineFilename, "r");
  if (fd == NULL) {
    printf("File does not exist\n");
    exit(-1);
  }
  fscanf(fd, "%f", &cosine);
  fclose(fd);
  printf("%f\n", sine + cosine);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xe,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11db <main+0x6b>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rdi
lea    0xe31(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    124d <main+0xdd>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rdi
lea    0xdbf(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movss  -0x14(%rbp),%xmm0
addss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdac(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0xe,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe6e(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     124d <main+0xcd>
mov    %rax,%rbx
lea    0xe3f(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1070 <fscanf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x10,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe19(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe05(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     124d <main+0xcd>
mov    %rax,%rbx
lea    0xdf0(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1070 <fscanf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
movss  0xc(%rsp),%xmm0
addss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd8(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xdc6(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"sineresult.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"File does not exist\0A\00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [17 x i8] c"cosineresult.txt\00"
@.str.5 = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca float
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i64 @malloc(i32 14)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %8
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %10
%17 = load i32*, i32** %10
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
%23 = load i32*, i32** %10
%24 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %6)
%25 = load i32*, i32** %10
%26 = call i32 @fclose(i32* %25)
%27 = call i64 @malloc(i32 16)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%31 = load i8*, i8** %9
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %10
%33 = load i32*, i32** %10
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %22
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %22
%39 = load i32*, i32** %10
%40 = call i32 @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %7)
%41 = load i32*, i32** %10
%42 = call i32 @fclose(i32* %41)
%43 = load float, float* %6
%44 = load float, float* %7
%45 = fadd float %43, %44
%46 = fpext float %45 to double
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"sineresult.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [17 x i8] c"cosineresult.txt\00"
@.str.5 = [4 x i8] c"%f\0A\00"
@str.6 = [20 x i8] c"File does not exist\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca float
%4 = alloca float
%5 = bitcast float* %3 to i8*
%6 = bitcast float* %4 to i8*
%7 = tail call i64 @malloc(i32 14)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32* @fopen(i8* %8, 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 = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %3)
%17 = call i32 @fclose(i32* %10)
%18 = call i64 @malloc(i32 16)
%19 = inttoptr i64 %18 to i8*
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %15
%27 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %4)
%28 = call i32 @fclose(i32* %21)
%29 = load float, float* %3
%30 = load float, float* %4
%31 = fadd float %29, %30
%32 = fpext float %31 to double
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double %32)
ret i32 0
}