#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  double height, sum, heightf;
  int n, i;
  printf("Input height: ");
  scanf("%lf", &height);
  printf("Input n: ");
  scanf("%d", &n);
  heightf = height;
  for (i = 1; i <= n + 1; i++) {
    sum = sum + heightf;
    height = height / 2.0;
    heightf = height * 2;
  }
  printf("distance=%.1f\n", sum);
  printf("height=%.1f\n", 2 * height);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jg     11d6 <main+0xb6>
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe53(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe42(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1180 <main+0x60>
movsd  -0x18(%rbp),%xmm0
lea    0xe46(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xe0f(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
lea    0xe3a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xedd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xede(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movsd  0x8(%rsp),%xmm2
mov    0x14(%rsp),%edx
lea    0x1(%rdx),%ecx
mov    %ecx,%eax
and    $0x3,%eax
cmp    $0x3,%edx
jae    1183 <main+0x63>
movapd %xmm2,%xmm1
jmp    11e5 <main+0xc5>
and    $0xfffffffc,%ecx
movsd  0xe72(%rip),%xmm3
movapd %xmm2,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
addsd  %xmm0,%xmm2
mulsd  %xmm3,%xmm1
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm3,%xmm1
movapd %xmm1,%xmm2
addsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm3,%xmm1
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm3,%xmm1
movapd %xmm1,%xmm2
addsd  %xmm1,%xmm2
add    $0xfffffffc,%ecx
jne    11a0 <main+0x80>
test   %eax,%eax
je     1215 <main+0xf5>
movsd  0xe0f(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
addsd  %xmm2,%xmm0
mulsd  %xmm3,%xmm1
movapd %xmm1,%xmm2
addsd  %xmm1,%xmm2
add    $0xffffffff,%eax
jne    1200 <main+0xe0>
movsd  %xmm1,0x8(%rsp)
lea    0xe06(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
lea    0xdfd(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Input height: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [10 x i8] c"Input n: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [15 x i8] c"distance=%.1f\0A\00"
@.str.5 = [13 x i8] c"height=%.1f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%11 = load double, double* %2
store double %11, double* %4
store i32 1, i32* %6
br label %12
12: ; preds = %25, %0
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
%16 = icmp sle i32 %13, %15
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = load double, double* %3
%19 = load double, double* %4
%20 = fadd double %18, %19
store double %20, double* %3
%21 = load double, double* %2
%22 = fdiv double %21, 2.000000e+00
store double %22, double* %2
%23 = load double, double* %2
%24 = fmul double %23, 2.000000e+00
store double %24, double* %4
br label %25
25: ; preds = %17
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %12
28: ; preds = %12
%29 = load double, double* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), double %29)
%31 = load double, double* %2
%32 = fmul double 2.000000e+00, %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), double %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Input height: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [10 x i8] c"Input n: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [15 x i8] c"distance=%.1f\0A\00"
@.str.5 = [13 x i8] c"height=%.1f\0A\00"
define i32 @main() {
%1 = alloca double
%2 = alloca i32
%3 = bitcast double* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%9 = load double, double* %1
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, -1
%12 = add nuw i32 %10, 1
%13 = and i32 %12, 3
%14 = icmp ult i32 %10, 3
br i1 %14, label %36, label %15
15: ; preds = %0
%16 = and i32 %12, -4
br label %17
17: ; preds = %17, %15
%18 = phi double [ %9, %15 ], [ %33, %17 ]
%19 = phi double [ undef, %15 ], [ %31, %17 ]
%20 = phi double [ %9, %15 ], [ %32, %17 ]
%21 = phi i32 [ 0, %15 ], [ %34, %17 ]
%22 = fadd double %19, %18
%23 = fmul double %20, 5.000000e-01
%24 = fmul double %23, 2.000000e+00
%25 = fadd double %22, %24
%26 = fmul double %23, 5.000000e-01
%27 = fmul double %26, 2.000000e+00
%28 = fadd double %25, %27
%29 = fmul double %26, 5.000000e-01
%30 = fmul double %29, 2.000000e+00
%31 = fadd double %28, %30
%32 = fmul double %29, 5.000000e-01
%33 = fmul double %32, 2.000000e+00
%34 = add i32 %21, 4
%35 = icmp eq i32 %34, %16
br i1 %35, label %36, label %17
36: ; preds = %17, %0
%37 = phi double [ undef, %0 ], [ %32, %17 ]
%38 = phi double [ %9, %0 ], [ %33, %17 ]
%39 = phi double [ undef, %0 ], [ %31, %17 ]
%40 = phi double [ %9, %0 ], [ %32, %17 ]
%41 = icmp eq i32 %13, 0
br i1 %41, label %52, label %42
42: ; preds = %36, %42
%43 = phi double [ %49, %42 ], [ %38, %36 ]
%44 = phi double [ %47, %42 ], [ %39, %36 ]
%45 = phi double [ %48, %42 ], [ %40, %36 ]
%46 = phi i32 [ %50, %42 ], [ 0, %36 ]
%47 = fadd double %44, %43
%48 = fmul double %45, 5.000000e-01
%49 = fmul double %48, 2.000000e+00
%50 = add i32 %46, 1
%51 = icmp eq i32 %50, %13
br i1 %51, label %52, label %42
52: ; preds = %42, %36
%53 = phi double [ %39, %36 ], [ %47, %42 ]
%54 = phi double [ %37, %36 ], [ %48, %42 ]
store double %54, double* %1
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), double %53)
%56 = load double, double* %1
%57 = fmul double %56, 2.000000e+00
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), double %57)
ret i32 0
}