#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 calc_get_error_code();
double calc_h_c(double, double, double);
double calc_h_g(double, double, double);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, double *, double *,
                          double *, double *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage:  hghc infile\n");
    exit(1);
  }
  FILE *inFile = fopen(argv[1], "r");
  if (!inFile) {
    fprintf(stderr, "Could not open file \"%s\"\n", argv[1]);
    exit(2);
  }
  FILE *outFile = fopen("outfile", "w+");
  if (!outFile) {
    fprintf(stderr, "Could not create output file.\n", argv[1]);
    exit(3);
  }
  while (!feof(inFile)) {
    double k_c, h_p, h_b, tau_c;
    fscanf(inFile, "%lf %lf %lf %lf", &k_c, &h_p, &h_b, &tau_c);
    double h_g = calc_h_g(k_c, h_p, tau_c);
    if (calc_get_error_code() == 1)
      fprintf(outFile, "[ERR: divide by zero] ");
    else
      fprintf(outFile, "%lf ", h_g);
    double h_c = calc_h_c(k_c, h_b, tau_c);
    if (calc_get_error_code() == 1)
      fprintf(outFile, "[ERR: divide by zero]\n");
    else
      fprintf(outFile, "%lf\n", h_c);
  }
  fclose(inFile);
  fclose(outFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d6 <main+0x36>
lea    0xe39(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe30(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1223 <main+0x83>
mov    0x2de0(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
lea    0xe07(%rip),%rdi
lea    0xe08(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    126f <main+0xcf>
mov    0x2d94(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>
jmp    1274 <main+0xd4>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1292 <main+0xf2>
jmp    1365 <main+0x1c5>
mov    -0x18(%rbp),%rdi
lea    0xdbe(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
lea    -0x40(%rbp),%r9
call   1060 <fscanf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
call   10a0 <calc_h_g@plt>
movsd  %xmm0,-0x48(%rbp)
mov    $0x0,%al
call   1040 <calc_get_error_code@plt>
cmp    $0x1,%eax
jne    12f2 <main+0x152>
mov    -0x20(%rbp),%rdi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1309 <main+0x169>
mov    -0x20(%rbp),%rdi
movsd  -0x48(%rbp),%xmm0
lea    0xd80(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
call   1090 <calc_h_c@plt>
movsd  %xmm0,-0x50(%rbp)
mov    $0x0,%al
call   1040 <calc_get_error_code@plt>
cmp    $0x1,%eax
jne    1349 <main+0x1a9>
mov    -0x20(%rbp),%rdi
lea    0xd4a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1360 <main+0x1c0>
mov    -0x20(%rbp),%rdi
movsd  -0x50(%rbp),%xmm0
lea    0xd45(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
jmp    1274 <main+0xd4>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jne    1330 <main+0x180>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe2b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1346 <main+0x196>
mov    %rax,%r14
lea    0xe2f(%rip),%rdi
lea    0xe30(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     136c <main+0x1bc>
mov    %rax,%rbx
mov    %r14,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1232 <main+0x82>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r12
lea    0x20(%rsp),%r13
lea    0x18(%rsp),%rbp
lea    0x8(%rsp),%r15
jmp    1272 <main+0xc2>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe2f(%rip),%rsi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1211 <main+0x61>
mov    %r14,%rdi
lea    0xdca(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
mov    %r15,%r9
call   1060 <fscanf@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   10a0 <calc_h_g@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <calc_get_error_code@plt>
cmp    $0x1,%eax
jne    12d0 <main+0x120>
mov    $0x16,%esi
mov    $0x1,%edx
lea    0xd90(%rip),%rdi
mov    %rbx,%rcx
call   10d0 <fwrite@plt>
jmp    12e6 <main+0x136>
mov    %rbx,%rdi
lea    0xd93(%rip),%rsi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   1090 <calc_h_c@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <calc_get_error_code@plt>
cmp    $0x1,%eax
jne    1250 <main+0xa0>
mov    $0x16,%esi
mov    $0x1,%edx
lea    0xd4f(%rip),%rdi
mov    %rbx,%rcx
call   10d0 <fwrite@plt>
jmp    1266 <main+0xb6>
lea    0xd57(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c93(%rip),%rax
movslq (%rax),%rdi
mov    0x8(%rbp),%rdx
lea    0xca7(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    0x2c6d(%rip),%rax
movslq (%rax),%rdi
mov    0x8(%rbp),%rdx
lea    0xca6(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Usage: hghc infile\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Could not open file \22%s\22\0A\00"
@.str.3 = [8 x i8] c"outfile\00"
@.str.4 = [3 x i8] c"w+\00"
@.str.5 = [31 x i8] c"Could not create output file.\0A\00"
@.str.6 = [16 x i8] c"%lf %lf %lf %lf\00"
@.str.7 = [23 x i8] c"[ERR: divide by zero] \00"
@.str.8 = [5 x i8] c"%lf \00"
@.str.9 = [23 x i8] c"[ERR: divide by zero]\0A\00"
@.str.10 = [5 x i8] c"%lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp ne i32* %24, null
br i1 %25, label %35, label %26
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 2)
unreachable
35: ; preds = %19
%36 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i32*, i32** %7
%38 = icmp ne i32* %37, null
br i1 %38, label %48, label %39
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = sext i32 %40 to i64
%42 = inttoptr i64 %41 to i32*
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 3)
unreachable
48: ; preds = %35
br label %49
49: ; preds = %84, %48
%50 = load i32*, i32** %6
%51 = call i32 @feof(i32* %50)
%52 = icmp ne i32 %51, 0
%53 = xor i1 %52, true
br i1 %53, label %54, label %85
54: ; preds = %49
%55 = load i32*, i32** %6
%56 = call i32 @fscanf(i32* %55, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), double* %8, double* %9, double* %10, double* %11)
%57 = load double, double* %8
%58 = load double, double* %9
%59 = load double, double* %11
%60 = call double @calc_h_g(double %57, double %58, double %59)
store double %60, double* %12
%61 = call i32 (...) @calc_get_error_code()
%62 = icmp eq i32 %61, 1
br i1 %62, label %63, label %66
63: ; preds = %54
%64 = load i32*, i32** %7
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %70
66: ; preds = %54
%67 = load i32*, i32** %7
%68 = load double, double* %12
%69 = call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), double %68)
br label %70
70: ; preds = %66, %63
%71 = load double, double* %8
%72 = load double, double* %10
%73 = load double, double* %11
%74 = call double @calc_h_c(double %71, double %72, double %73)
store double %74, double* %13
%75 = call i32 (...) @calc_get_error_code()
%76 = icmp eq i32 %75, 1
br i1 %76, label %77, label %80
77: ; preds = %70
%78 = load i32*, i32** %7
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %78, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
br label %84
80: ; preds = %70
%81 = load i32*, i32** %7
%82 = load double, double* %13
%83 = call i32 (i32*, i8*, ...) @fprintf(i32* %81, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), double %82)
br label %84
84: ; preds = %80, %77
br label %49
85: ; preds = %49
%86 = load i32*, i32** %6
%87 = call i32 @fclose(i32* %86)
%88 = load i32*, i32** %7
%89 = call i32 @fclose(i32* %88)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Could not open file \22%s\22\0A\00"
@.str.3 = [8 x i8] c"outfile\00"
@.str.4 = [3 x i8] c"w+\00"
@.str.5 = [31 x i8] c"Could not create output file.\0A\00"
@.str.6 = [16 x i8] c"%lf %lf %lf %lf\00"
@.str.7 = [23 x i8] c"[ERR: divide by zero] \00"
@.str.8 = [5 x i8] c"%lf \00"
@.str.9 = [23 x i8] c"[ERR: divide by zero]\0A\00"
@.str.10 = [5 x i8] c"%lf\0A\00"
@str = [20 x i8] c"Usage: hghc infile\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
%20 = load i8*, i8** %12
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 2)
unreachable
23: ; preds = %11
%24 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %34, label %26
26: ; preds = %23
%27 = call i32 @feof(i32* %14)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %67
29: ; preds = %26
%30 = bitcast double* %3 to i8*
%31 = bitcast double* %4 to i8*
%32 = bitcast double* %5 to i8*
%33 = bitcast double* %6 to i8*
br label %41
34: ; preds = %23
%35 = load i32, i32* @stderr
%36 = sext i32 %35 to i64
%37 = inttoptr i64 %36 to i32*
%38 = load i8*, i8** %12
%39 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%40 = tail call i32 @exit(i32 3)
unreachable
41: ; preds = %29, %64
%42 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), double* %3, double* %4, double* %5, double* %6)
%43 = load double, double* %3
%44 = load double, double* %4
%45 = load double, double* %6
%46 = call double @calc_h_g(double %43, double %44, double %45)
%47 = call i32 (...) @calc_get_error_code()
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %51
49: ; preds = %41
%50 = call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i64 22, i64 1, i32* %24)
br label %53
51: ; preds = %41
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), double %46)
br label %53
53: ; preds = %51, %49
%54 = load double, double* %3
%55 = load double, double* %5
%56 = load double, double* %6
%57 = call double @calc_h_c(double %54, double %55, double %56)
%58 = call i32 (...) @calc_get_error_code()
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %62
60: ; preds = %53
%61 = call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i64 22, i64 1, i32* %24)
br label %64
62: ; preds = %53
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), double %57)
br label %64
64: ; preds = %62, %60
%65 = call i32 @feof(i32* %14)
%66 = icmp eq i32 %65, 0
br i1 %66, label %41, label %67
67: ; preds = %64, %26
%68 = call i32 @fclose(i32* %14)
%69 = call i32 @fclose(i32* %24)
ret i32 0
}