#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 zahl;
  printf("Fritz und Hans essen Aepfel\n");
  printf("===========================\n");
  printf("Druecke 'q' zum beenden.\n");
  while (run) {
    printf("\n   Wieviele Aepfel haben Fritz und Hans gekauft? ");
    int inputok = scanf("%u", &zahl);
    if (!inputok) {
      char quit = getchar();
      if (quit == 'q' || quit == 'Q')
        run = 0;
      printf("Eingabe ist keine gueltige positive Ganzzahl!\n");
      continue;
    }
    if (zahl % 8) {
      printf("Die Zahl ist nicht durch 8 teilbar.\n");
      continue;
    }
    unsigned int fritz = 0, hans = 0, runde = 1;
    printf("Runde | Fritz |  Hans |  Rest |\n");
    printf("------+-------+-------+-------|\n");
    while (zahl > 0) {
      printf("%5u | %5u | %5u | %5u |\n", runde++, fritz += 5, hans += 3,
             zahl -= 8);
    }
  }
  printf("Die Anwendung wurde vom Benutzer beendet.");
  fflush(stdin);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     1291 <main+0x151>
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11f3 <main+0xb3>
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    11e0 <main+0xa0>
movl   $0x0,-0x8(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1180 <main+0x40>
mov    -0xc(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
je     1215 <main+0xd5>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1180 <main+0x40>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jbe    128c <main+0x14c>
mov    -0x20(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edx
add    $0x5,%edx
mov    %edx,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
add    $0x3,%ecx
mov    %ecx,-0x1c(%rbp)
mov    -0xc(%rbp),%r8d
sub    $0x8,%r8d
mov    %r8d,-0xc(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1246 <main+0x106>
jmp    1180 <main+0x40>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf17(%rip),%rdi
call   1030 <puts@plt>
lea    0xf27(%rip),%rdi
call   1030 <puts@plt>
lea    0xf37(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7a(%rip),%r15
lea    0xea6(%rip),%r12
lea    0x4(%rsp),%rbx
lea    0xf31(%rip),%r13
lea    0xe96(%rip),%rbp
jmp    11d3 <main+0x83>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
and    $0xdf,%al
xor    %r14d,%r14d
cmp    $0x51,%al
setne  %r14b
mov    %r13,%rdi
call   1030 <puts@plt>
test   %r14d,%r14d
je     1298 <main+0x148>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
test   %eax,%eax
je     11b0 <main+0x60>
mov    $0x1,%r14d
testb  $0x7,0x4(%rsp)
lea    0xf3a(%rip),%rdi
jne    11c5 <main+0x75>
lea    0xef1(%rip),%rdi
call   1030 <puts@plt>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%r8d
test   %r8d,%r8d
je     128d <main+0x13d>
mov    %r15,%rbx
mov    $0x1,%r14d
mov    $0x3,%r12d
mov    $0x5,%r13d
mov    $0x1,%esi
nopl   0x0(%rax)
lea    0x1(%rsi),%r15d
add    $0xfffffff8,%r8d
mov    %r8d,0x4(%rsp)
mov    %rbp,%rdi
mov    %r13d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%r8d
add    $0x3,%r12d
add    $0x5,%r13d
mov    %r15d,%esi
test   %r8d,%r8d
jne    1240 <main+0xf0>
mov    %rbx,%r15
lea    0xdb7(%rip),%r12
lea    0x4(%rsp),%rbx
lea    0xe42(%rip),%r13
jmp    11ca <main+0x7a>
mov    $0x1,%r14d
jmp    11ca <main+0x7a>
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Fritz und Hans essen Aepfel\0A\00"
@.str.1 = [29 x i8] c"===========================\0A\00"
@.str.2 = [26 x i8] c"Druecke 'q' zum beenden.\0A\00"
@.str.3 = [51 x i8] c"\0A Wieviele Aepfel haben Fritz und Hans gekauft? \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 = [37 x i8] c"Die Zahl ist nicht durch 8 teilbar.\0A\00"
@.str.7 = [33 x i8] c"Runde | Fritz | Hans | Rest |\0A\00"
@.str.8 = [33 x i8] c"------+-------+-------+-------|\0A\00"
@.str.9 = [25 x i8] c"%5u | %5u | %5u | %5u |\0A\00"
@.str.10 = [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 i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %54, %36, %30, %0
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %55
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %32, label %20
20: ; preds = %15
%21 = call signext i8 (...) @getchar()
store i8 %21, i8* %5
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 113
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = load i8, i8* %5
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 81
br i1 %28, label %29, label %30
29: ; preds = %25, %20
store i32 0, i32* %2
br label %30
30: ; preds = %29, %25
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
br label %12
32: ; preds = %15
%33 = load i32, i32* %3
%34 = urem i32 %33, 8
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
br label %12
38: ; preds = %32
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %41
41: ; preds = %44, %38
%42 = load i32, i32* %3
%43 = icmp ugt i32 %42, 0
br i1 %43, label %44, label %54
44: ; preds = %41
%45 = load i32, i32* %8
%46 = add i32 %45, 1
store i32 %46, i32* %8
%47 = load i32, i32* %6
%48 = add i32 %47, 5
store i32 %48, i32* %6
%49 = load i32, i32* %7
%50 = add i32 %49, 3
store i32 %50, i32* %7
%51 = load i32, i32* %3
%52 = sub i32 %51, 8
store i32 %52, i32* %3
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %45, i32 %48, i32 %50, i32 %52)
br label %41
54: ; preds = %41
br label %12
55: ; preds = %12
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0))
%57 = load i32, i32* @stdin
%58 = call i32 @fflush(i32 %57)
%59 = call signext i8 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [51 x i8] c"\0A Wieviele Aepfel haben Fritz und Hans gekauft? \00"
@.str.4 = [3 x i8] c"%u\00"
@.str.9 = [25 x i8] c"%5u | %5u | %5u | %5u |\0A\00"
@.str.10 = [42 x i8] c"Die Anwendung wurde vom Benutzer beendet.\00"
@stdin = global i32 0
@str = [28 x i8] c"Fritz und Hans essen Aepfel\00"
@str.11 = [28 x i8] c"===========================\00"
@str.12 = [25 x i8] c"Druecke 'q' zum beenden.\00"
@str.13 = [46 x i8] c"Eingabe ist keine gueltige positive Ganzzahl!\00"
@str.14 = [32 x i8] c"Runde | Fritz | Hans | Rest |\00"
@str.15 = [32 x i8] c"------+-------+-------+-------|\00"
@str.16 = [36 x i8] c"Die Zahl ist nicht durch 8 teilbar.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
br label %6
6: ; preds = %0, %40
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 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 %10, label %15
10: ; preds = %6
%11 = call signext i8 (...) @getchar()
%12 = and i8 %11, -33
%13 = icmp ne i8 %12, 81
%14 = zext i1 %13 to i32
br label %36
15: ; preds = %6
%16 = load i32, i32* %1
%17 = and i32 %16, 7
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.14, i64 0, i64 0))
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.15, i64 0, i64 0))
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, 0
br i1 %23, label %40, label %24
24: ; preds = %19, %24
%25 = phi i32 [ %34, %24 ], [ %22, %19 ]
%26 = phi i32 [ %29, %24 ], [ 1, %19 ]
%27 = phi i32 [ %31, %24 ], [ 0, %19 ]
%28 = phi i32 [ %30, %24 ], [ 0, %19 ]
%29 = add i32 %26, 1
%30 = add i32 %28, 5
%31 = add i32 %27, 3
%32 = add i32 %25, -8
store i32 %32, i32* %1
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %26, i32 %30, i32 %31, i32 %32)
%34 = load i32, i32* %1
%35 = icmp eq i32 %34, 0
br i1 %35, label %40, label %24
36: ; preds = %15, %10
%37 = phi i8* [ getelementptr inbounds ([46 x i8], [46 x i8]* @str.13, i64 0, i64 0), %10 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.16, i64 0, i64 0), %15 ]
%38 = phi i32 [ %14, %10 ], [ 1, %15 ]
%39 = call i32 @puts(i8* dereferenceable(1) %37)
br label %40
40: ; preds = %24, %36, %19
%41 = phi i32 [ 1, %19 ], [ %38, %36 ], [ 1, %24 ]
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %6
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0))
%45 = load i32, i32* @stdin
%46 = call i32 @fflush(i32 %45)
%47 = call signext i8 (...) @getchar()
ret i32 0
}