#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 = 0, sum1;
  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;
    for (j = 1; j < i; j++) {
      sum1 = 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
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebe(%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     11f8 <main+0xb8>
movsd  0xe66(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    11db <main+0x9b>
movsd  -0x38(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
divsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11a6 <main+0x66>
movsd  -0x38(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1186 <main+0x46>
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    0xdea(%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>:
push   %rbx
sub    $0x30,%rsp
lea    0xec4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    0x28(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1060 <scanf@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    121b <main+0xdb>
movsd  0xe75(%rip),%xmm0
divsd  0x28(%rsp),%xmm0
xorpd  %xmm3,%xmm3
mov    $0x1,%ecx
movsd  0xe66(%rip),%xmm1
jmp    11c0 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
addsd  %xmm2,%xmm3
lea    0x1(%rcx),%edx
add    $0x1,%ebx
cmp    %eax,%ecx
mov    %edx,%ecx
je     121f <main+0xdf>
movapd %xmm1,%xmm2
cmp    $0x2,%ecx
jb     11b0 <main+0x70>
lea    -0x1(%rbx),%edx
movapd %xmm1,%xmm2
cmp    $0x7,%edx
jb     1205 <main+0xc5>
mov    %ebx,%edx
and    $0xfffffff8,%edx
movapd %xmm1,%xmm2
xchg   %ax,%ax
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
add    $0xfffffff8,%edx
jne    11e0 <main+0xa0>
test   $0x7,%bl
je     11b0 <main+0x70>
mov    %ebx,%edx
and    $0x7,%edx
nop
mulsd  %xmm0,%xmm2
add    $0xffffffff,%edx
jne    1210 <main+0xd0>
jmp    11b0 <main+0x70>
xorpd  %xmm3,%xmm3
movsd  %xmm3,0x20(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x10(%rsp),%eax
mov    0x14(%rsp),%ecx
sub    0x18(%rsp),%eax
sub    0x1c(%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    0xdbf(%rip),%rdi
movsd  0x20(%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0x30,%rsp
pop    %rbx
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 0.000000e+00, double* %7
%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 = %36, %0
%16 = load i32, i32* %9
%17 = load i32, i32* %11
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %39
19: ; preds = %15
store double 1.000000e+00, double* %8
store i32 1, i32* %10
br label %20
20: ; preds = %29, %19
%21 = load i32, i32* %10
%22 = load i32, i32* %9
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load double, double* %8
%26 = load double, double* %6
%27 = fdiv double -1.000000e+00, %26
%28 = fmul double %25, %27
store double %28, double* %8
br label %29
29: ; preds = %24
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %20
32: ; preds = %20
%33 = load double, double* %8
%34 = load double, double* %7
%35 = fadd double %34, %33
store double %35, double* %7
br label %36
36: ; preds = %32
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %15
39: ; preds = %15
%40 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%44 = load i32, i32* %43
%45 = sub nsw i32 %42, %44
%46 = mul nsw i32 %45, 1000
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%50 = load i32, i32* %49
%51 = sub nsw i32 %48, %50
%52 = sdiv i32 %51, 1000
%53 = add nsw i32 %46, %52
%54 = sext i32 %53 to i64
store i64 %54, i64* %5
%55 = load double, double* %7
%56 = load i64, i64* %5
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), double %55, i64 %56)
%58 = 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
br label %17
17: ; preds = %14, %51
%18 = phi i32 [ 0, %14 ], [ %56, %51 ]
%19 = phi i32 [ 1, %14 ], [ %54, %51 ]
%20 = phi double [ 0.000000e+00, %14 ], [ %53, %51 ]
%21 = icmp ugt i32 %19, 1
br i1 %21, label %22, label %51
22: ; preds = %17
%23 = add i32 %18, -1
%24 = and i32 %18, 7
%25 = icmp ult i32 %23, 7
br i1 %25, label %41, label %26
26: ; preds = %22
%27 = and i32 %18, -8
br label %28
28: ; preds = %28, %26
%29 = phi double [ 1.000000e+00, %26 ], [ %38, %28 ]
%30 = phi i32 [ 0, %26 ], [ %39, %28 ]
%31 = fmul double %29, %16
%32 = fmul double %31, %16
%33 = fmul double %32, %16
%34 = fmul double %33, %16
%35 = fmul double %34, %16
%36 = fmul double %35, %16
%37 = fmul double %36, %16
%38 = fmul double %37, %16
%39 = add i32 %30, 8
%40 = icmp eq i32 %39, %27
br i1 %40, label %41, label %28
41: ; preds = %28, %22
%42 = phi double [ undef, %22 ], [ %38, %28 ]
%43 = phi double [ 1.000000e+00, %22 ], [ %38, %28 ]
%44 = icmp eq i32 %24, 0
br i1 %44, label %51, label %45
45: ; preds = %41, %45
%46 = phi double [ %48, %45 ], [ %43, %41 ]
%47 = phi i32 [ %49, %45 ], [ 0, %41 ]
%48 = fmul double %46, %16
%49 = add i32 %47, 1
%50 = icmp eq i32 %49, %24
br i1 %50, label %51, label %45
51: ; preds = %41, %45, %17
%52 = phi double [ 1.000000e+00, %17 ], [ %42, %41 ], [ %48, %45 ]
%53 = fadd double %20, %52
%54 = add nuw i32 %19, 1
%55 = icmp eq i32 %19, %12
%56 = add i32 %18, 1
br i1 %55, label %57, label %17
57: ; preds = %51, %0
%58 = phi double [ 0.000000e+00, %0 ], [ %53, %51 ]
%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
}