#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*/ time_t;
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *, int *);
void main() {
  time_t t1, t2;
  struct timeval tv1, tv2;
  long t;
  double x, sum = 1, sum1 = 1;
  int i, j, n;
  printf("Please input x, n:");
  scanf("%lf%d", &x, &n);
  gettimeofday(&tv1, NULL);
  for (i = 1; i <= n; i++) {
    sum1 *= -1.0 / x;
    sum += sum1;
  }
  gettimeofday(&tv2, NULL);
  t = (tv2.tv_sec - tv1.tv_sec) * 1000 + (tv2.tv_usec - tv1.tv_usec) / 1000;
  printf("sum=%1f use easpled: %ld ms\n", sum, t);
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  0xeb0(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xea3(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   1060 <scanf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jg     11d8 <main+0x98>
movsd  0xe5c(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1198 <main+0x58>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x48(%rbp)
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rsi
lea    0xe0a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    0x20(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1060 <scanf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
jle    11a5 <main+0x65>
movsd  0xe84(%rip),%xmm0
divsd  0x20(%rsp),%xmm0
lea    -0x1(%rcx),%edx
mov    %ecx,%eax
and    $0x7,%eax
cmp    $0x7,%edx
jae    11af <main+0x6f>
movsd  0xe61(%rip),%xmm2
movapd %xmm2,%xmm1
jmp    1205 <main+0xc5>
movsd  0xe53(%rip),%xmm2
jmp    121d <main+0xdd>
and    $0xfffffff8,%ecx
movsd  0xe46(%rip),%xmm2
movapd %xmm2,%xmm1
xchg   %ax,%ax
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
add    $0xfffffff8,%ecx
jne    11c0 <main+0x80>
test   %eax,%eax
je     121d <main+0xdd>
nopl   0x0(%rax)
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
add    $0xffffffff,%eax
jne    1210 <main+0xd0>
movsd  %xmm2,0x18(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x10(%rsp),%eax
sub    0x14(%rsp),%ecx
imul   $0x3e8,%eax,%eax
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %eax,%ecx
movslq %ecx,%rsi
lea    0xdc1(%rip),%rdi
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [19 x i8] c"Please input x, n:\00"
@.str.1 = [6 x i8] c"%lf%d\00"
@.str.2 = [29 x i8] c"sum=%1f use easpled: %ld ms\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i64
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store double 1.000000e+00, double* %7
store double 1.000000e+00, double* %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double* %6, i32* %11)
%14 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
store i32 1, i32* %9
br label %15
15: ; preds = %27, %0
%16 = load i32, i32* %9
%17 = load i32, i32* %11
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load double, double* %6
%21 = fdiv double -1.000000e+00, %20
%22 = load double, double* %8
%23 = fmul double %22, %21
store double %23, double* %8
%24 = load double, double* %8
%25 = load double, double* %7
%26 = fadd double %25, %24
store double %26, double* %7
br label %27
27: ; preds = %19
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
br label %15
30: ; preds = %15
%31 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%35 = load i32, i32* %34
%36 = sub nsw i32 %33, %35
%37 = mul nsw i32 %36, 1000
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%41 = load i32, i32* %40
%42 = sub nsw i32 %39, %41
%43 = sdiv i32 %42, 1000
%44 = add nsw i32 %37, %43
%45 = sext i32 %44 to i64
store i64 %45, i64* %5
%46 = load double, double* %7
%47 = load i64, i64* %5
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), double %46, i64 %47)
%49 = call i32 (...) @getchar()
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [19 x i8] c"Please input x, n:\00"
@.str.1 = [6 x i8] c"%lf%d\00"
@.str.2 = [29 x i8] c"sum=%1f use easpled: %ld ms\0A\00"
define void @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = alloca double
%4 = alloca i32
%5 = bitcast %struct.timeval* %1 to i8*
%6 = bitcast %struct.timeval* %2 to i8*
%7 = bitcast double* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double* %3, i32* %4)
%11 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 1
br i1 %13, label %57, label %14
14: ; preds = %0
%15 = load double, double* %3
%16 = fdiv double -1.000000e+00, %15
%17 = add i32 %12, -1
%18 = and i32 %12, 7
%19 = icmp ult i32 %17, 7
br i1 %19, label %44, label %20
20: ; preds = %14
%21 = and i32 %12, -8
br label %22
22: ; preds = %22, %20
%23 = phi double [ 1.000000e+00, %20 ], [ %41, %22 ]
%24 = phi double [ 1.000000e+00, %20 ], [ %40, %22 ]
%25 = phi i32 [ 0, %20 ], [ %42, %22 ]
%26 = fmul double %24, %16
%27 = fadd double %23, %26
%28 = fmul double %26, %16
%29 = fadd double %27, %28
%30 = fmul double %28, %16
%31 = fadd double %29, %30
%32 = fmul double %30, %16
%33 = fadd double %31, %32
%34 = fmul double %32, %16
%35 = fadd double %33, %34
%36 = fmul double %34, %16
%37 = fadd double %35, %36
%38 = fmul double %36, %16
%39 = fadd double %37, %38
%40 = fmul double %38, %16
%41 = fadd double %39, %40
%42 = add i32 %25, 8
%43 = icmp eq i32 %42, %21
br i1 %43, label %44, label %22
44: ; preds = %22, %14
%45 = phi double [ undef, %14 ], [ %41, %22 ]
%46 = phi double [ 1.000000e+00, %14 ], [ %41, %22 ]
%47 = phi double [ 1.000000e+00, %14 ], [ %40, %22 ]
%48 = icmp eq i32 %18, 0
br i1 %48, label %57, label %49
49: ; preds = %44, %49
%50 = phi double [ %54, %49 ], [ %46, %44 ]
%51 = phi double [ %53, %49 ], [ %47, %44 ]
%52 = phi i32 [ %55, %49 ], [ 0, %44 ]
%53 = fmul double %51, %16
%54 = fadd double %50, %53
%55 = add i32 %52, 1
%56 = icmp eq i32 %55, %18
br i1 %56, label %57, label %49
57: ; preds = %44, %49, %0
%58 = phi double [ 1.000000e+00, %0 ], [ %45, %44 ], [ %54, %49 ]
%59 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%63 = load i32, i32* %62
%64 = sub nsw i32 %61, %63
%65 = mul nsw i32 %64, 1000
%66 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%67 = load i32, i32* %66
%68 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%69 = load i32, i32* %68
%70 = sub nsw i32 %67, %69
%71 = sdiv i32 %70, 1000
%72 = add nsw i32 %71, %65
%73 = sext i32 %72 to i64
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), double %58, i64 %73)
%75 = call i32 (...) @getchar()
ret void
}