#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*/ fflush(int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, unsigned int *);
int /*<<< orphan*/ stdin;
int main(void) {
  int run = 1;
  unsigned int input;
  printf("Berechnung der Leibniz-Reihe\n");
  printf("========================================\n");
  printf("Druecke 'q' zum beenden.\n");
  while (run) {
    printf("\nWieviele Brueche sollen addiert, bzw. subtrahiert werden? ");
    int inputok = scanf("%u", &input);
    if (!inputok) {
      char quit = getchar();
      if (quit == 'q' || quit == 'Q')
        break;
      printf("Eingabe ist keine gueltige positive Ganzzahl!\n");
      continue;
    }
    double toggle = 1, summe = 0;
    for (unsigned int i = 1, j = 1; i <= input; i++, j += 2, toggle *= -1)
      summe += 1.0 / j * toggle;
    printf("  Summe bis zum %u. Glied: %f ===> PI=%f\n", input, summe,
           4 * summe);
  }
  printf("Die Anwendung wurde vom Benutzer beendet.");
  fflush(stdin);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     129c <main+0x15c>
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf17(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11f1 <main+0xb1>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x71,%eax
je     11d9 <main+0x99>
movsbl -0x11(%rbp),%eax
cmp    $0x51,%eax
jne    11de <main+0x9e>
jmp    129c <main+0x15c>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1180 <main+0x40>
movsd  0xe07(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     1274 <main+0x134>
mov    -0x30(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  0xdd0(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x30(%rbp)
movsd  0xdab(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1214 <main+0xd4>
mov    -0xc(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  0xd84(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
lea    0xe58(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    1180 <main+0x40>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xf3f(%rip),%rdi
call   1030 <puts@plt>
lea    0xf50(%rip),%rdi
call   1030 <puts@plt>
lea    0xf6d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe88(%rip),%r14
lea    0xebd(%rip),%r15
lea    0xc(%rsp),%rbx
lea    0xf67(%rip),%r12
lea    0xead(%rip),%r13
jmp    11ca <main+0x7a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorpd  %xmm0,%xmm0
movapd %xmm0,%xmm1
mulsd  0xe48(%rip),%xmm1
mov    %r13,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
test   %eax,%eax
je     1200 <main+0xb0>
mov    0xc(%rsp),%esi
test   %esi,%esi
je     11b0 <main+0x60>
cmp    $0x1,%esi
jne    121b <main+0xcb>
xorpd  %xmm0,%xmm0
mov    $0x1,%eax
jmp    1275 <main+0x125>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
and    $0xdf,%al
cmp    $0x51,%al
je     129e <main+0x14e>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    11ca <main+0x7a>
mov    %esi,%ecx
and    $0xfffffffe,%ecx
xorpd  %xmm0,%xmm0
mov    $0x1,%eax
movsd  0xdcf(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%edx
xorps  %xmm1,%xmm1
cvtsi2sd %rdx,%xmm1
movapd %xmm3,%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
lea    0x2(%rax),%edx
xorps  %xmm1,%xmm1
cvtsi2sd %rdx,%xmm1
movapd %xmm3,%xmm2
divsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
add    $0x4,%eax
add    $0xfffffffe,%ecx
jne    1240 <main+0xf0>
test   $0x1,%sil
je     11b4 <main+0x64>
mov    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  0xd6f(%rip),%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
jmp    11b4 <main+0x64>
lea    0xdd4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Berechnung der Leibniz-Reihe\0A\00"
@.str.1 = [42 x i8] c"========================================\0A\00"
@.str.2 = [26 x i8] c"Druecke 'q' zum beenden.\0A\00"
@.str.3 = [60 x i8] c"\0AWieviele Brueche sollen addiert, bzw. subtrahiert werden? \00"
@.str.4 = [3 x i8] c"%u\00"
@.str.5 = [47 x i8] c"Eingabe ist keine gueltige positive Ganzzahl!\0A\00"
@.str.6 = [42 x i8] c" Summe bis zum %u. Glied: %f ===> PI=%f\0A\00"
@.str.7 = [42 x i8] c"Die Anwendung wurde vom Benutzer beendet.\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %52, %31, %0
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %58
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 0
br i1 %20, label %33, label %21
21: ; preds = %16
%22 = call signext i8 (...) @getchar()
store i8 %22, i8* %5
%23 = load i8, i8* %5
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 113
br i1 %25, label %30, label %26
26: ; preds = %21
%27 = load i8, i8* %5
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 81
br i1 %29, label %30, label %31
30: ; preds = %26, %21
br label %58
31: ; preds = %26
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
br label %13
33: ; preds = %16
store double 1.000000e+00, double* %6
store double 0.000000e+00, double* %7
store i32 1, i32* %8
store i32 1, i32* %9
br label %34
34: ; preds = %45, %33
%35 = load i32, i32* %8
%36 = load i32, i32* %3
%37 = icmp ule i32 %35, %36
br i1 %37, label %38, label %52
38: ; preds = %34
%39 = load i32, i32* %9
%40 = uitofp i32 %39 to double
%41 = fdiv double 1.000000e+00, %40
%42 = load double, double* %6
%43 = load double, double* %7
%44 = call double @llvm.fmuladd.f64(double %41, double %42, double %43)
store double %44, double* %7
br label %45
45: ; preds = %38
%46 = load i32, i32* %8
%47 = add i32 %46, 1
store i32 %47, i32* %8
%48 = load i32, i32* %9
%49 = add i32 %48, 2
store i32 %49, i32* %9
%50 = load double, double* %6
%51 = fmul double %50, -1.000000e+00
store double %51, double* %6
br label %34
52: ; preds = %34
%53 = load i32, i32* %3
%54 = load double, double* %7
%55 = load double, double* %7
%56 = fmul double 4.000000e+00, %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i32 %53, double %54, double %56)
br label %13
58: ; preds = %30, %13
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0))
%60 = load i32, i32* @stdin
%61 = call i32 @fflush(i32 %60)
%62 = call signext i8 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [60 x i8] c"\0AWieviele Brueche sollen addiert, bzw. subtrahiert werden? \00"
@.str.4 = [3 x i8] c"%u\00"
@.str.6 = [42 x i8] c" Summe bis zum %u. Glied: %f ===> PI=%f\0A\00"
@.str.7 = [42 x i8] c"Die Anwendung wurde vom Benutzer beendet.\00"
@stdin = global i32 0
@str = [29 x i8] c"Berechnung der Leibniz-Reihe\00"
@str.8 = [41 x i8] c"========================================\00"
@str.9 = [25 x i8] c"Druecke 'q' zum beenden.\00"
@str.10 = [46 x i8] c"Eingabe ist keine gueltige positive Ganzzahl!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.8, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.9, i64 0, i64 0))
br label %6
6: ; preds = %24, %0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %6
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 0
br i1 %12, label %34, label %13
13: ; preds = %10
%14 = and i32 %11, 1
%15 = icmp eq i32 %11, 1
br i1 %15, label %25, label %16
16: ; preds = %13
%17 = and i32 %11, -2
br label %38
18: ; preds = %6
%19 = call signext i8 (...) @getchar()
%20 = and i8 %19, -33
%21 = icmp eq i8 %20, 81
br i1 %21, label %52, label %22
22: ; preds = %18
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.10, i64 0, i64 0))
br label %24
24: ; preds = %22, %34
br label %6
25: ; preds = %38, %13
%26 = phi double [ undef, %13 ], [ %48, %38 ]
%27 = phi i32 [ 1, %13 ], [ %49, %38 ]
%28 = phi double [ 0.000000e+00, %13 ], [ %48, %38 ]
%29 = icmp eq i32 %14, 0
br i1 %29, label %34, label %30
30: ; preds = %25
%31 = uitofp i32 %27 to double
%32 = fdiv double 1.000000e+00, %31
%33 = fadd double %32, %28
br label %34
34: ; preds = %30, %25, %10
%35 = phi double [ 0.000000e+00, %10 ], [ %26, %25 ], [ %33, %30 ]
%36 = fmul double %35, 4.000000e+00
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i32 %11, double %35, double %36)
br label %24
38: ; preds = %38, %16
%39 = phi i32 [ 1, %16 ], [ %49, %38 ]
%40 = phi double [ 0.000000e+00, %16 ], [ %48, %38 ]
%41 = phi i32 [ 0, %16 ], [ %50, %38 ]
%42 = uitofp i32 %39 to double
%43 = fdiv double 1.000000e+00, %42
%44 = fadd double %43, %40
%45 = add nuw nsw i32 %39, 2
%46 = uitofp i32 %45 to double
%47 = fdiv double 1.000000e+00, %46
%48 = call double @llvm.fmuladd.f64(double %47, double -1.000000e+00, double %44)
%49 = add i32 %39, 4
%50 = add i32 %41, 2
%51 = icmp eq i32 %50, %17
br i1 %51, label %25, label %38
52: ; preds = %18
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0))
%54 = load i32, i32* @stdin
%55 = call i32 @fflush(i32 %54)
%56 = call signext i8 (...) @getchar()
ret i32 0
}