#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 f(double);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  double a, b, c, ea;
  a = -2;
  b = -1;
  int n, i;
  n = 30;
  for (i = 0; i < n; i++) {
    c = (a + b) / 2;
    if (f(a) * f(c) < 0) {
      printf("1\n");
      b = c;
    } else if (f(a) * f(c) > 0) {
      printf("x\n");
      a = c;
    } else {
      printf("%lf\n", c);
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xed1(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1e,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    123f <main+0x11f>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe9b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,-0x34(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
imul   %ecx,%eax
cmp    $0x0,%eax
jge    11c3 <main+0xa3>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    122c <main+0x10c>
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
imul   %ecx,%eax
cmp    $0x0,%eax
jle    1208 <main+0xe8>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1227 <main+0x107>
movsd  -0x20(%rbp),%xmm0
lea    0xe0a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123f <main+0x11f>
jmp    122c <main+0x10c>
jmp    1231 <main+0x111>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1157 <main+0x37>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  0xebe(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xeb8(%rip),%xmm0
mov    $0x1e,%ebp
lea    0xec3(%rip),%r14
lea    0xeba(%rip),%r15
jmp    118e <main+0x5e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
movsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1030 <puts@plt>
add    $0xffffffff,%ebp
movsd  0x8(%rsp),%xmm0
je     1204 <main+0xd4>
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
mulsd  0xe70(%rip),%xmm1
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1040 <f@plt>
mov    %eax,%ebx
movsd  (%rsp),%xmm0
call   1040 <f@plt>
imul   %ebx,%eax
test   %eax,%eax
js     1170 <main+0x40>
movsd  0x8(%rsp),%xmm0
call   1040 <f@plt>
mov    %eax,%ebx
movsd  (%rsp),%xmm0
call   1040 <f@plt>
imul   %ebx,%eax
test   %eax,%eax
jle    11f1 <main+0xc1>
mov    %r15,%rdi
movsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    117e <main+0x4e>
lea    0xe20(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"1\0A\00"
@.str.1 = [3 x i8] c"x\0A\00"
@.str.2 = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store double -2.000000e+00, double* %2
store double -1.000000e+00, double* %3
store i32 30, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %41, %0
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %44
12: ; preds = %8
%13 = load double, double* %2
%14 = load double, double* %3
%15 = fadd double %13, %14
%16 = fdiv double %15, 2.000000e+00
store double %16, double* %4
%17 = load double, double* %2
%18 = call i32 @f(double %17)
%19 = load double, double* %4
%20 = call i32 @f(double %19)
%21 = mul nsw i32 %18, %20
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%25 = load double, double* %4
store double %25, double* %3
br label %40
26: ; preds = %12
%27 = load double, double* %2
%28 = call i32 @f(double %27)
%29 = load double, double* %4
%30 = call i32 @f(double %29)
%31 = mul nsw i32 %28, %30
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = load double, double* %4
store double %35, double* %2
br label %39
36: ; preds = %26
%37 = load double, double* %4
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %37)
store i32 0, i32* %1
br label %44
39: ; preds = %33
br label %40
40: ; preds = %39, %23
br label %41
41: ; preds = %40
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %8
44: ; preds = %36, %8
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str.2 = [5 x i8] c"%lf\0A\00"
@str = [2 x i8] c"x\00"
@str.3 = [2 x i8] c"1\00"
define i32 @main() {
br label %1
1: ; preds = %0, %18
%2 = phi i32 [ 0, %0 ], [ %23, %18 ]
%3 = phi double [ -2.000000e+00, %0 ], [ %21, %18 ]
%4 = phi double [ -1.000000e+00, %0 ], [ %20, %18 ]
%5 = fadd double %4, %3
%6 = fmul double %5, 5.000000e-01
%7 = tail call i32 @f(double %3)
%8 = tail call i32 @f(double %6)
%9 = mul nsw i32 %8, %7
%10 = icmp slt i32 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %1
%12 = tail call i32 @f(double %3)
%13 = tail call i32 @f(double %6)
%14 = mul nsw i32 %13, %12
%15 = icmp sgt i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %6)
br label %25
18: ; preds = %11, %1
%19 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.3, i64 0, i64 0), %1 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0), %11 ]
%20 = phi double [ %6, %1 ], [ %4, %11 ]
%21 = phi double [ %3, %1 ], [ %6, %11 ]
%22 = tail call i32 @puts(i8* dereferenceable(1) %19)
%23 = add nuw nsw i32 %2, 1
%24 = icmp eq i32 %23, 30
br i1 %24, label %25, label %1
25: ; preds = %18, %16
ret i32 0
}