#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 *);
int main(void) {
  double pos, neg, minus;
  int i, j, limit;
  printf("How much is the limit? (<=0 to quit) :\n");
  scanf("%d", &limit);
  while (limit > 0) {
    for (i = 1, j = 1, pos = 0.0, neg = 0.0, minus = -1.0; i <= limit;
         i++, j++) {
      pos += 1.0 / i;
      minus *= -1.0;
      neg += 1.0 / (minus * j);
    }
    printf("Pos = %f and Neg = %f after %d times!\n", pos, neg, limit);
    printf("How much is the limit? (<=0 to quit) :\n");
    scanf("%d", &limit);
  }
  printf("Thank you!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef4(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    1234 <main+0x114>
movl   $0x1,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe83(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jg     11f6 <main+0xd6>
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  0xe6d(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe4f(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
cvtsi2sdl -0x28(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe37(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1182 <main+0x62>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x2c(%rbp),%esi
lea    0xe31(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe12(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <scanf@plt>
jmp    114d <main+0x2d>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xf26(%rip),%rdi
call   1030 <puts@plt>
lea    0xee5(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    1276 <main+0x146>
lea    0xecb(%rip),%r14
lea    0xef6(%rip),%r15
lea    0xeba(%rip),%r12
lea    0x4(%rsp),%rbx
movsd  0xe7d(%rip),%xmm4
movapd 0xe85(%rip),%xmm5
movapd 0xe8d(%rip),%xmm6
jmp    11e9 <main+0xb9>
cs nopw 0x0(%rax,%rax,1)
nop
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
mov    %r14,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movsd  0xe33(%rip),%xmm4
mov    0x4(%rsp),%esi
test   %esi,%esi
movapd 0xe35(%rip),%xmm5
movapd 0xe3d(%rip),%xmm6
jle    1276 <main+0x146>
cmp    $0x1,%esi
jne    1200 <main+0xd0>
xorpd  %xmm1,%xmm1
mov    $0x1,%eax
jmp    1250 <main+0x120>
nopl   0x0(%rax)
mov    %esi,%ecx
and    $0xfffffffe,%ecx
xorpd  %xmm1,%xmm1
mov    $0x1,%eax
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd %xmm4,%xmm2
divsd  %xmm0,%xmm2
unpcklpd %xmm2,%xmm2
addpd  %xmm1,%xmm2
lea    0x1(%rax),%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movapd %xmm0,%xmm3
xorpd  %xmm5,%xmm3
unpcklpd %xmm0,%xmm3
movapd %xmm6,%xmm1
divpd  %xmm3,%xmm1
addpd  %xmm2,%xmm1
add    $0x2,%eax
cmp    %ecx,%edx
jne    1210 <main+0xe0>
test   $0x1,%sil
je     11a0 <main+0x70>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd %xmm4,%xmm2
divsd  %xmm0,%xmm2
unpcklpd %xmm2,%xmm2
addpd  %xmm2,%xmm1
jmp    11a0 <main+0x70>
lea    0xddd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [40 x i8] c"How much is the limit? (<=0 to quit) :\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"Pos = %f and Neg = %f after %d times!\0A\00"
@.str.3 = [11 x i8] c"Thank you!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
br label %10
10: ; preds = %38, %0
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %45
13: ; preds = %10
store i32 1, i32* %5
store i32 1, i32* %6
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
store double -1.000000e+00, double* %4
br label %14
14: ; preds = %33, %13
%15 = load i32, i32* %5
%16 = load i32, i32* %7
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %38
18: ; preds = %14
%19 = load i32, i32* %5
%20 = sitofp i32 %19 to double
%21 = fdiv double 1.000000e+00, %20
%22 = load double, double* %2
%23 = fadd double %22, %21
store double %23, double* %2
%24 = load double, double* %4
%25 = fmul double %24, -1.000000e+00
store double %25, double* %4
%26 = load double, double* %4
%27 = load i32, i32* %6
%28 = sitofp i32 %27 to double
%29 = fmul double %26, %28
%30 = fdiv double 1.000000e+00, %29
%31 = load double, double* %3
%32 = fadd double %31, %30
store double %32, double* %3
br label %33
33: ; preds = %18
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %14
38: ; preds = %14
%39 = load double, double* %2
%40 = load double, double* %3
%41 = load i32, i32* %7
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), double %39, double %40, i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
br label %10
45: ; preds = %10
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"Pos = %f and Neg = %f after %d times!\0A\00"
@.str.3 = [11 x i8] c"Thank you!\00"
@str.4 = [39 x i8] c"How much is the limit? (<=0 to quit) :\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.4, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %52
7: ; preds = %0, %43
%8 = phi i32 [ %50, %43 ], [ %5, %0 ]
%9 = and i32 %8, 1
%10 = icmp eq i32 %8, 1
br i1 %10, label %32, label %11
11: ; preds = %7
%12 = and i32 %8, -2
br label %13
13: ; preds = %13, %11
%14 = phi i32 [ 1, %11 ], [ %29, %13 ]
%15 = phi <2 x double> [ zeroinitializer, %11 ], [ %28, %13 ]
%16 = phi i32 [ 0, %11 ], [ %30, %13 ]
%17 = sitofp i32 %14 to double
%18 = insertelement <2 x double> poison, double %17, i64 0
%19 = fdiv <2 x double> <double 1.000000e+00, double poison>, %18
%20 = shufflevector <2 x double> %19, <2 x double> poison, <2 x i32> zeroinitializer
%21 = fadd <2 x double> %15, %20
%22 = add nuw i32 %14, 1
%23 = sitofp i32 %22 to double
%24 = fneg double %23
%25 = insertelement <2 x double> poison, double %24, i64 0
%26 = insertelement <2 x double> %25, double %23, i64 1
%27 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %26
%28 = fadd <2 x double> %21, %27
%29 = add nuw i32 %14, 2
%30 = add i32 %16, 2
%31 = icmp eq i32 %30, %12
br i1 %31, label %32, label %13
32: ; preds = %13, %7
%33 = phi <2 x double> [ undef, %7 ], [ %28, %13 ]
%34 = phi i32 [ 1, %7 ], [ %29, %13 ]
%35 = phi <2 x double> [ zeroinitializer, %7 ], [ %28, %13 ]
%36 = icmp eq i32 %9, 0
br i1 %36, label %43, label %37
37: ; preds = %32
%38 = sitofp i32 %34 to double
%39 = insertelement <2 x double> poison, double %38, i64 0
%40 = fdiv <2 x double> <double 1.000000e+00, double poison>, %39
%41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> zeroinitializer
%42 = fadd <2 x double> %35, %41
br label %43
43: ; preds = %32, %37
%44 = phi <2 x double> [ %33, %32 ], [ %42, %37 ]
%45 = extractelement <2 x double> %44, i64 0
%46 = extractelement <2 x double> %44, i64 1
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), double %46, double %45, i32 %8)
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.4, i64 0, i64 0))
%49 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%50 = load i32, i32* %1
%51 = icmp sgt i32 %50, 0
br i1 %51, label %7, label %52
52: ; preds = %43, %0
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}