#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("Alle Teiler einer Zahl\n");
  printf("======================\n");
  printf("Druecke 'q' zum beenden.\n");
  while (run) {
    printf("\nGib eine Zahl ein: ");
    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;
    }
    unsigned int haelfte = zahl / 2, nointro = 1, hits = 0;
    for (unsigned int i = 2; i <= haelfte; i++)
      if (!(zahl % i)) {
        hits++;
        if (nointro) {
          nointro = 0;
          printf("%u ist teilbar durch: %u", zahl, i);
        } else
          printf(", %u", i);
      }
    if (!hits)
      printf("%u ist eine Primzahl.\n", zahl);
  }
  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    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     12aa <main+0x16a>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0a(%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    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1180 <main+0x40>
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
ja     128a <main+0x14a>
mov    -0xc(%rbp),%eax
xor    %edx,%edx
divl   -0x24(%rbp)
cmp    $0x0,%edx
jne    1277 <main+0x137>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1261 <main+0x121>
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1272 <main+0x132>
mov    -0x24(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1277 <main+0x137>
jmp    127c <main+0x13c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1211 <main+0xd1>
cmpl   $0x0,-0x20(%rbp)
jne    12a5 <main+0x165>
mov    -0xc(%rbp),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1180 <main+0x40>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d29(%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   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf12(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1d(%rip),%rdi
call   1030 <puts@plt>
lea    0xf28(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7a(%rip),%r14
lea    0xea3(%rip),%r15
lea    0x4(%rsp),%rbp
lea    0xe95(%rip),%r12
jmp    11bf <main+0x6f>
nopl   0x0(%rax,%rax,1)
mov    0x4(%rsp),%esi
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
test   %ebx,%ebx
je     12a1 <main+0x151>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
test   %eax,%eax
je     1280 <main+0x130>
mov    0x4(%rsp),%esi
cmp    $0x4,%esi
jb     11a0 <main+0x50>
mov    %r14,%rbp
mov    %esi,%r14d
shr    %r14d
mov    $0x1,%ebx
xor    %r15d,%r15d
mov    $0x2,%r13d
nopl   0x0(%rax)
mov    %esi,%eax
xor    %edx,%edx
div    %r13d
test   %edx,%edx
jne    1222 <main+0xd2>
add    $0x1,%r15d
test   %ebx,%ebx
jne    1231 <main+0xe1>
xor    %ebx,%ebx
mov    %r12,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r13d,%r14d
je     1250 <main+0x100>
add    $0x1,%r13d
mov    0x4(%rsp),%esi
jmp    1200 <main+0xb0>
xor    %ebx,%ebx
lea    0xddb(%rip),%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r13d,%r14d
jne    1227 <main+0xd7>
nopl   0x0(%rax)
mov    $0x1,%ebx
test   %r15d,%r15d
mov    %rbp,%r14
lea    0xdce(%rip),%r15
lea    0x4(%rsp),%rbp
jne    11b7 <main+0x67>
jmp    11a0 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
and    $0xdf,%al
xor    %ebx,%ebx
cmp    $0x51,%al
setne  %bl
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
jmp    11b7 <main+0x67>
lea    0xda2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d32(%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 = [24 x i8] c"Alle Teiler einer Zahl\0A\00"
@.str.1 = [24 x i8] c"======================\0A\00"
@.str.2 = [26 x i8] c"Druecke 'q' zum beenden.\0A\00"
@.str.3 = [21 x i8] c"\0AGib eine Zahl ein: \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 = [25 x i8] c"%u ist teilbar durch: %u\00"
@.str.7 = [5 x i8] c", %u\00"
@.str.8 = [23 x i8] c"%u ist eine Primzahl.\0A\00"
@.str.9 = [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
%9 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 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 = %68, %31, %0
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %69
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 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
store i32 0, i32* %2
br label %31
31: ; preds = %30, %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
%34 = load i32, i32* %3
%35 = udiv i32 %34, 2
store i32 %35, i32* %6
store i32 1, i32* %7
store i32 0, i32* %8
store i32 2, i32* %9
br label %36
36: ; preds = %59, %33
%37 = load i32, i32* %9
%38 = load i32, i32* %6
%39 = icmp ule i32 %37, %38
br i1 %39, label %40, label %62
40: ; preds = %36
%41 = load i32, i32* %3
%42 = load i32, i32* %9
%43 = urem i32 %41, %42
%44 = icmp ne i32 %43, 0
br i1 %44, label %58, label %45
45: ; preds = %40
%46 = load i32, i32* %8
%47 = add i32 %46, 1
store i32 %47, i32* %8
%48 = load i32, i32* %7
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %45
store i32 0, i32* %7
%51 = load i32, i32* %3
%52 = load i32, i32* %9
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %51, i32 %52)
br label %57
54: ; preds = %45
%55 = load i32, i32* %9
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %54, %50
br label %58
58: ; preds = %57, %40
br label %59
59: ; preds = %58
%60 = load i32, i32* %9
%61 = add i32 %60, 1
store i32 %61, i32* %9
br label %36
62: ; preds = %36
%63 = load i32, i32* %8
%64 = icmp ne i32 %63, 0
br i1 %64, label %68, label %65
65: ; preds = %62
%66 = load i32, i32* %3
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %65, %62
br label %13
69: ; preds = %13
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
%71 = load i32, i32* @stdin
%72 = call i32 @fflush(i32 %71)
%73 = call signext i8 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [21 x i8] c"\0AGib eine Zahl ein: \00"
@.str.4 = [3 x i8] c"%u\00"
@.str.6 = [25 x i8] c"%u ist teilbar durch: %u\00"
@.str.7 = [5 x i8] c", %u\00"
@.str.8 = [23 x i8] c"%u ist eine Primzahl.\0A\00"
@.str.9 = [42 x i8] c"Die Anwendung wurde vom Benutzer beendet.\00"
@stdin = global i32 0
@str = [23 x i8] c"Alle Teiler einer Zahl\00"
@str.10 = [23 x i8] c"======================\00"
@str.11 = [25 x i8] c"Druecke 'q' zum beenden.\00"
@str.12 = [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 ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.11, i64 0, i64 0))
br label %6
6: ; preds = %0, %47
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 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 %16
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
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.12, i64 0, i64 0))
br label %47
16: ; preds = %6
%17 = load i32, i32* %1
%18 = icmp ult i32 %17, 4
br i1 %18, label %44, label %19
19: ; preds = %16
%20 = lshr i32 %17, 1
br label %23
21: ; preds = %37
%22 = icmp eq i32 %39, 0
br i1 %22, label %44, label %47
23: ; preds = %41, %19
%24 = phi i32 [ %43, %41 ], [ %17, %19 ]
%25 = phi i32 [ %42, %41 ], [ 2, %19 ]
%26 = phi i32 [ %39, %41 ], [ 0, %19 ]
%27 = phi i32 [ %38, %41 ], [ 1, %19 ]
%28 = urem i32 %24, %25
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %23
%31 = add i32 %26, 1
%32 = icmp eq i32 %27, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %24, i32 %25)
br label %37
35: ; preds = %30
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %25)
br label %37
37: ; preds = %23, %35, %33
%38 = phi i32 [ %27, %23 ], [ 0, %33 ], [ 0, %35 ]
%39 = phi i32 [ %26, %23 ], [ %31, %33 ], [ %31, %35 ]
%40 = icmp eq i32 %25, %20
br i1 %40, label %21, label %41
41: ; preds = %37
%42 = add nuw i32 %25, 1
%43 = load i32, i32* %1
br label %23
44: ; preds = %16, %21
%45 = load i32, i32* %1
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %21, %44, %10
%48 = phi i32 [ %14, %10 ], [ 1, %44 ], [ 1, %21 ]
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %6
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
%52 = load i32, i32* @stdin
%53 = call i32 @fflush(i32 %52)
%54 = call signext i8 (...) @getchar()
ret i32 0
}