#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 scanf(char *, float *);
int main() {
  int limit = 3000;
  float grenzwert;
  float aktuell = 0.0;
  int pos = 1;
  int neg = 2;
  printf("Gewünschter Grenzwert: ");
  if (scanf("%f", &grenzwert) != 1) {
    printf("Bitte eine Zahl eingeben!\n");
    return 1;
  }
  for (int i = 0; i < limit; i++) {
    if (aktuell < grenzwert) {
      aktuell += 1.0 / pos;
      printf("+ 1/%4d", pos);
      pos += 2;
    } else {
      aktuell -= 1.0 / neg;
      printf("- 1/%4d", neg);
      neg += 2;
    }
    printf(", aktuell: %+8f, Fehler: %+8f\n", aktuell, aktuell - grenzwert);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xbb8,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     118d <main+0x6d>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1274 <main+0x154>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    126d <main+0x14d>
movss  -0x10(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    11f9 <main+0xd9>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe40(%rip),%xmm1
divsd  %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    123a <main+0x11a>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xdfa(%rip),%xmm1
divsd  %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
subss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xdf7(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1194 <main+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed6(%rip),%rdi
lea    0x14(%rsp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1245 <main+0x115>
xorps  %xmm2,%xmm2
mov    $0x1,%r13d
mov    $0x2,%ebp
mov    $0xbb8,%ebx
lea    0xeac(%rip),%r14
lea    0xeb5(%rip),%r15
lea    0xea6(%rip),%r12
jmp    11fc <main+0xcc>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  0xe61(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
add    $0x2,%ebp
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
subss  0x14(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mov    %r15,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movss  0x8(%rsp),%xmm2
add    $0xffffffff,%ebx
je     1258 <main+0x128>
movss  0x14(%rsp),%xmm0
ucomiss %xmm2,%xmm0
jbe    1190 <main+0x60>
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
movsd  0xdf1(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
add    $0x2,%r13d
jmp    11c9 <main+0x99>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    125a <main+0x12a>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Gew\C3\BCnschter Grenzwert: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [27 x i8] c"Bitte eine Zahl eingeben!\0A\00"
@.str.3 = [8 x i8] c"+ 1/%4d\00"
@.str.4 = [8 x i8] c"- 1/%4d\00"
@.str.5 = [31 x i8] c", aktuell: %+8f, Fehler: %+8f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 3000, i32* %2
store float 0.000000e+00, float* %4
store i32 1, i32* %5
store i32 2, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 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), float* %3)
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %58
13: ; preds = %0
store i32 0, i32* %7
br label %14
14: ; preds = %54, %13
%15 = load i32, i32* %7
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %57
18: ; preds = %14
%19 = load float, float* %4
%20 = load float, float* %3
%21 = fcmp olt float %19, %20
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load i32, i32* %5
%24 = sitofp i32 %23 to double
%25 = fdiv double 1.000000e+00, %24
%26 = load float, float* %4
%27 = fpext float %26 to double
%28 = fadd double %27, %25
%29 = fptrunc double %28 to float
store float %29, float* %4
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 2
store i32 %33, i32* %5
br label %46
34: ; preds = %18
%35 = load i32, i32* %6
%36 = sitofp i32 %35 to double
%37 = fdiv double 1.000000e+00, %36
%38 = load float, float* %4
%39 = fpext float %38 to double
%40 = fsub double %39, %37
%41 = fptrunc double %40 to float
store float %41, float* %4
%42 = load i32, i32* %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 2
store i32 %45, i32* %6
br label %46
46: ; preds = %34, %22
%47 = load float, float* %4
%48 = fpext float %47 to double
%49 = load float, float* %4
%50 = load float, float* %3
%51 = fsub float %49, %50
%52 = fpext float %51 to double
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), double %48, double %52)
br label %54
54: ; preds = %46
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %14
57: ; preds = %14
store i32 0, i32* %1
br label %58
58: ; preds = %57, %11
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@.str = [25 x i8] c"Gew\C3\BCnschter Grenzwert: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.3 = [8 x i8] c"+ 1/%4d\00"
@.str.4 = [8 x i8] c"- 1/%4d\00"
@.str.5 = [31 x i8] c", aktuell: %+8f, Fehler: %+8f\0A\00"
@str = [26 x i8] c"Bitte eine Zahl eingeben!\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %41
8: ; preds = %0, %29
%9 = phi i32 [ %39, %29 ], [ 0, %0 ]
%10 = phi i32 [ %32, %29 ], [ 2, %0 ]
%11 = phi i32 [ %31, %29 ], [ 1, %0 ]
%12 = phi float [ %33, %29 ], [ 0.000000e+00, %0 ]
%13 = load float, float* %1
%14 = fcmp olt float %12, %13
br i1 %14, label %15, label %22
15: ; preds = %8
%16 = sitofp i32 %11 to double
%17 = fdiv double 1.000000e+00, %16
%18 = fpext float %12 to double
%19 = fadd double %17, %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%21 = add nsw i32 %11, 2
br label %29
22: ; preds = %8
%23 = sitofp i32 %10 to double
%24 = fdiv double 1.000000e+00, %23
%25 = fpext float %12 to double
%26 = fsub double %25, %24
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%28 = add nsw i32 %10, 2
br label %29
29: ; preds = %22, %15
%30 = phi double [ %19, %15 ], [ %26, %22 ]
%31 = phi i32 [ %21, %15 ], [ %11, %22 ]
%32 = phi i32 [ %10, %15 ], [ %28, %22 ]
%33 = fptrunc double %30 to float
%34 = fpext float %33 to double
%35 = load float, float* %1
%36 = fsub float %33, %35
%37 = fpext float %36 to double
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), double %34, double %37)
%39 = add nuw nsw i32 %9, 1
%40 = icmp eq i32 %39, 3000
br i1 %40, label %41, label %8
41: ; preds = %29, %6
%42 = phi i32 [ 1, %6 ], [ 0, %29 ]
ret i32 %42
}