#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
double atof(char *);
double definite_integral_f1_dx(double, double, double, double);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
double x_intercept(double);
int main(int argc, char **argv) {
  double x = 0.0;
  double r = 3.0;
  double a = -1.0;
  double b = 0.0;
  switch (argc) {
  case 2:
    x = atof(argv[1]);
    break;
  default:
    fprintf(stderr,
            "Usage: %s x"
            "\n",
            argv[0]);
    exit(EXIT_FAILURE);
    break;
  }
  fprintf(stdout, "x = %lf\n", x);
  fprintf(stdout, "r = %lf\n", r);
  a = 0.0;
  b = x_intercept(r);
  fprintf(stdout, "x-intercept is at %lf\n", b);
  fprintf(stdout, "area under curve(-1.0, 0.0] = 1.5\n");
  fprintf(stdout, "area under curve(%lf, %lf) = %lf\n", a, b,
          definite_integral_f1_dx(r, x, a, b));
  fprintf(stdout, "total area under curve(-1.0,x-intercept) = %lf\n",
          1.5 + definite_integral_f1_dx(r, x, a, b));
  return (EXIT_SUCCESS);
}


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)
movq   $0x0,-0x18(%rbp)
movabs $0x4008000000000000,%rax
mov    %rax,-0x20(%rbp)
movabs $0xbff0000000000000,%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
jne    11ba <main+0x6a>
jmp    11a3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11e6 <main+0x96>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
movsd  -0x18(%rbp),%xmm0
lea    0xe1a(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
movsd  -0x20(%rbp),%xmm0
lea    0xe07(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <x_intercept@plt>
movsd  %xmm0,-0x30(%rbp)
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
movsd  -0x30(%rbp),%xmm0
lea    0xddd(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
call   1060 <definite_integral_f1_dx@plt>
mov    -0x4c(%rbp),%edi
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
lea    0xda9(%rip),%rsi
mov    $0x3,%al
call   1050 <fprintf@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
call   1060 <definite_integral_f1_dx@plt>
mov    -0x34(%rbp),%edi
movaps %xmm0,%xmm1
movsd  0xd0e(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xd86(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2cbd(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1258 <main+0x108>
mov    0x8(%rsi),%rdi
call   1030 <atof@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x2e5a(%rip),%r14
mov    (%r14),%edi
lea    0xe9d(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    (%r14),%edi
lea    0xe95(%rip),%rsi
movsd  0xe67(%rip),%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
movsd  0xe58(%rip),%xmm0
call   1040 <x_intercept@plt>
movsd  %xmm0,0x8(%rsp)
mov    (%r14),%edi
lea    0xe72(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    (%r14),%edi
lea    0xe78(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%ebx
xorps  %xmm2,%xmm2
movsd  0xe1d(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm3
call   1060 <definite_integral_f1_dx@plt>
movaps %xmm0,%xmm2
lea    0xe6b(%rip),%rsi
xorps  %xmm0,%xmm0
mov    %ebx,%edi
movsd  0x8(%rsp),%xmm1
mov    $0x3,%al
call   1050 <fprintf@plt>
mov    (%r14),%ebx
xorps  %xmm2,%xmm2
movsd  0xde2(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm3
call   1060 <definite_integral_f1_dx@plt>
addsd  0xdd1(%rip),%xmm0
lea    0xe4d(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xda5(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"Usage: %s x\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [9 x i8] c"x = %lf\0A\00"
@.str.2 = [9 x i8] c"r = %lf\0A\00"
@.str.3 = [23 x i8] c"x-intercept is at %lf\0A\00"
@.str.4 = [35 x i8] c"area under curve(-1.0, 0.0] = 1.5\0A\00"
@.str.5 = [34 x i8] c"area under curve(%lf, %lf) = %lf\0A\00"
@.str.6 = [48 x i8] c"total area under curve(-1.0,x-intercept) = %lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %6
store double 3.000000e+00, double* %7
store double -1.000000e+00, double* %8
store double 0.000000e+00, double* %9
%10 = load i32, i32* %4
switch i32 %10, label %16 [
i32 2, label %11
]
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call double @atof(i8* %14)
store double %15, double* %6
br label %24
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %11
%25 = load i32, i32* @stdout
%26 = load double, double* %6
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %26)
%28 = load i32, i32* @stdout
%29 = load double, double* %7
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %29)
store double 0.000000e+00, double* %8
%31 = load double, double* %7
%32 = call double @x_intercept(double %31)
store double %32, double* %9
%33 = load i32, i32* @stdout
%34 = load double, double* %9
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %34)
%36 = load i32, i32* @stdout
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32, i32* @stdout
%39 = load double, double* %8
%40 = load double, double* %9
%41 = load double, double* %7
%42 = load double, double* %6
%43 = load double, double* %8
%44 = load double, double* %9
%45 = call double @definite_integral_f1_dx(double %41, double %42, double %43, double %44)
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), double %39, double %40, double %45)
%47 = load i32, i32* @stdout
%48 = load double, double* %7
%49 = load double, double* %6
%50 = load double, double* %8
%51 = load double, double* %9
%52 = call double @definite_integral_f1_dx(double %48, double %49, double %50, double %51)
%53 = fadd double 1.500000e+00, %52
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), double %53)
%55 = load i32, i32* @EXIT_SUCCESS
ret i32 %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"Usage: %s x\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [9 x i8] c"x = %lf\0A\00"
@.str.2 = [9 x i8] c"r = %lf\0A\00"
@.str.3 = [23 x i8] c"x-intercept is at %lf\0A\00"
@.str.4 = [35 x i8] c"area under curve(-1.0, 0.0] = 1.5\0A\00"
@.str.5 = [34 x i8] c"area under curve(%lf, %lf) = %lf\0A\00"
@.str.6 = [48 x i8] c"total area under curve(-1.0,x-intercept) = %lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %25
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call double @atof(i8* %6)
%8 = load i32, i32* @stdout
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %7)
%10 = load i32, i32* @stdout
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double 3.000000e+00)
%12 = tail call double @x_intercept(double 3.000000e+00)
%13 = load i32, i32* @stdout
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %12)
%15 = load i32, i32* @stdout
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = tail call double @definite_integral_f1_dx(double 3.000000e+00, double %7, double 0.000000e+00, double %12)
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), double 0.000000e+00, double %12, double %18)
%20 = load i32, i32* @stdout
%21 = tail call double @definite_integral_f1_dx(double 3.000000e+00, double %7, double 0.000000e+00, double %12)
%22 = fadd double %21, 1.500000e+00
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), double %22)
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %1
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
}