#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;
int /*<<< orphan*/ checkIntInput(int *, int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int n, x;
  double sum = 1, numerator = 1, denumerator = 1;
  printf("Enter n and x: ");
  checkIntInput(&n, &x);
  if (x == 0) {
    printf("x must be > from 0!");
    exit(EXIT_FAILURE);
  }
  int i;
  for (i = 1; i <= n; i++) {
    numerator *= i;
    denumerator *= x;
    sum += numerator / denumerator;
  }
  printf("result: %.5lf", sum);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xeb9(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeac(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe9f(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <checkIntInput@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11a7 <main+0x77>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11fa <main+0xca>
cvtsi2sdl -0x2c(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ae <main+0x7e>
movsd  -0x18(%rbp),%xmm0
lea    0xe26(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <checkIntInput@plt>
mov    (%rsp),%ecx
test   %ecx,%ecx
je     1220 <main+0xf0>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    1185 <main+0x55>
cvtsi2sd %ecx,%xmm1
cmp    $0x1,%eax
jne    118f <main+0x5f>
movsd  0xe90(%rip),%xmm4
movapd %xmm4,%xmm2
movapd %xmm4,%xmm3
movapd %xmm4,%xmm0
test   $0x1,%al
jne    11f7 <main+0xc7>
jmp    1207 <main+0xd7>
movsd  0xe73(%rip),%xmm0
jmp    1207 <main+0xd7>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movsd  0xe64(%rip),%xmm2
mov    $0x1,%edx
movapd %xmm2,%xmm3
movapd %xmm2,%xmm0
nopl   0x0(%rax)
xorps  %xmm4,%xmm4
cvtsi2sd %edx,%xmm4
mulsd  %xmm3,%xmm4
mulsd  %xmm1,%xmm2
lea    0x1(%rdx),%esi
xorps  %xmm3,%xmm3
cvtsi2sd %esi,%xmm3
mulsd  %xmm4,%xmm3
divsd  %xmm2,%xmm4
addsd  %xmm0,%xmm4
mulsd  %xmm1,%xmm2
movapd %xmm3,%xmm0
divsd  %xmm2,%xmm0
addsd  %xmm4,%xmm0
add    $0x2,%edx
cmp    %ecx,%esi
jne    11b0 <main+0x80>
xorps  %xmm4,%xmm4
cvtsi2sd %edx,%xmm4
test   $0x1,%al
je     1207 <main+0xd7>
mulsd  %xmm4,%xmm3
mulsd  %xmm1,%xmm2
divsd  %xmm2,%xmm3
addsd  %xmm3,%xmm0
lea    0xe1e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"Enter n and x: \00"
@.str.1 = [20 x i8] c"x must be > from 0!\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [14 x i8] c"result: %.5lf\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store i32 0, i32* %1
store double 1.000000e+00, double* %4
store double 1.000000e+00, double* %5
store double 1.000000e+00, double* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @checkIntInput(i32* %2, i32* %3)
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
store i32 1, i32* %7
br label %17
17: ; preds = %35, %16
%18 = load i32, i32* %7
%19 = load i32, i32* %2
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = load i32, i32* %7
%23 = sitofp i32 %22 to double
%24 = load double, double* %5
%25 = fmul double %24, %23
store double %25, double* %5
%26 = load i32, i32* %3
%27 = sitofp i32 %26 to double
%28 = load double, double* %6
%29 = fmul double %28, %27
store double %29, double* %6
%30 = load double, double* %5
%31 = load double, double* %6
%32 = fdiv double %30, %31
%33 = load double, double* %4
%34 = fadd double %33, %32
store double %34, double* %4
br label %35
35: ; preds = %21
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %17
38: ; preds = %17
%39 = load double, double* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %39)
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
}

LLVM IR (-O2):
@.str = [16 x i8] c"Enter n and x: \00"
@.str.1 = [20 x i8] c"x must be > from 0!\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [14 x i8] c"result: %.5lf\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @checkIntInput(i32* %1, i32* %2)
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %0
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
br i1 %11, label %56, label %12
12: ; preds = %9
%13 = sitofp i32 %7 to double
%14 = and i32 %10, 1
%15 = icmp eq i32 %10, 1
br i1 %15, label %44, label %16
16: ; preds = %12
%17 = and i32 %10, -2
br label %22
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %22, %16
%23 = phi i32 [ 1, %16 ], [ %39, %22 ]
%24 = phi double [ 1.000000e+00, %16 ], [ %36, %22 ]
%25 = phi double [ 1.000000e+00, %16 ], [ %35, %22 ]
%26 = phi double [ 1.000000e+00, %16 ], [ %38, %22 ]
%27 = phi i32 [ 0, %16 ], [ %40, %22 ]
%28 = sitofp i32 %23 to double
%29 = fmul double %25, %28
%30 = fmul double %24, %13
%31 = fdiv double %29, %30
%32 = fadd double %26, %31
%33 = add nuw i32 %23, 1
%34 = sitofp i32 %33 to double
%35 = fmul double %29, %34
%36 = fmul double %30, %13
%37 = fdiv double %35, %36
%38 = fadd double %32, %37
%39 = add nuw i32 %23, 2
%40 = add i32 %27, 2
%41 = icmp eq i32 %40, %17
br i1 %41, label %42, label %22
42: ; preds = %22
%43 = sitofp i32 %39 to double
br label %44
44: ; preds = %42, %12
%45 = phi double [ undef, %12 ], [ %38, %42 ]
%46 = phi double [ 1.000000e+00, %12 ], [ %43, %42 ]
%47 = phi double [ 1.000000e+00, %12 ], [ %36, %42 ]
%48 = phi double [ 1.000000e+00, %12 ], [ %35, %42 ]
%49 = phi double [ 1.000000e+00, %12 ], [ %38, %42 ]
%50 = icmp eq i32 %14, 0
br i1 %50, label %56, label %51
51: ; preds = %44
%52 = fmul double %48, %46
%53 = fmul double %47, %13
%54 = fdiv double %52, %53
%55 = fadd double %49, %54
br label %56
56: ; preds = %51, %44, %9
%57 = phi double [ 1.000000e+00, %9 ], [ %45, %44 ], [ %55, %51 ]
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %57)
%59 = load i32, i32* @EXIT_SUCCESS
ret i32 %59
}