#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*/);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int main(void) {
  int zahl;
  printf("Quersumme zu einer Zahl\n");
  printf("=======================\n\n");
  printf("Zahl? ");
  while (!scanf("%d", &zahl)) {
    printf("Zahl muss eine Ganzzahl sein.\nZahl? ");
    fflush(stdin);
  }
  printf("      Dualdarstellung zu %i: ", zahl);
  for (int i = 31; i >= 0; i--) {
    printf("%i", (zahl >> i) & 1);
    if (!(i % 8))
      printf(" ");
  }
  printf("\nDuale BCD-Darstellung zu %i: ", zahl);
  int divisor = 10;
  while (zahl / divisor)
    divisor *= 10;
  divisor /= 10;
  while (divisor) {
    int part = zahl / divisor;
    for (int i = 3; i >= 0; i--)
      printf("%i", (part >> i) & 1);
    printf(" ");
    zahl %= divisor;
    divisor /= 10;
  }
  fflush(stdin);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119e <main+0x5e>
jmp    11bf <main+0x7f>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    1179 <main+0x39>
mov    -0x8(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1f,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     122f <main+0xef>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%ecx
sar    %cl,%esi
and    $0x1,%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    121c <main+0xdc>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <main+0xe1>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11d7 <main+0x97>
mov    -0x8(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xa,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%eax
je     1263 <main+0x123>
imul   $0xa,-0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1247 <main+0x107>
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     12ea <main+0x1aa>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     12bd <main+0x17d>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%ecx
sar    %cl,%esi
and    $0x1,%esi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    128c <main+0x14c>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
jmp    1271 <main+0x131>
mov    0x2cf7(%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   %rbx
push   %rax
lea    0xefa(%rip),%rdi
call   1040 <puts@plt>
lea    0xf06(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe6c(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jne    11e1 <main+0x81>
lea    0xe5a(%rip),%r14
mov    0x2e38(%rip),%r15
lea    0xe49(%rip),%rbp
lea    0x4(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%edi
call   1070 <fflush@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
test   %eax,%eax
je     11c0 <main+0x60>
mov    0x4(%rsp),%esi
lea    0xe3c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1f,%ebx
lea    0xe47(%rip),%rbp
jmp    1215 <main+0xb5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
jae    123b <main+0xdb>
mov    0x4(%rsp),%esi
mov    %ebx,%ecx
shr    %cl,%esi
and    $0x1,%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0x7,%bl
jne    1210 <main+0xb0>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0xb0>
mov    0x4(%rsp),%esi
lea    0xe03(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%ecx
lea    0x9(%rcx),%eax
mov    $0xa,%esi
cmp    $0x13,%eax
jb     1287 <main+0x127>
mov    $0xa,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %esi,%esi
lea    (%rsi,%rsi,4),%esi
mov    %ecx,%eax
cltd
idiv   %esi
test   %eax,%eax
jne    1270 <main+0x110>
cmp    $0xa,%esi
jb     1325 <main+0x1c5>
mov    %esi,%eax
mov    $0xcccccccd,%ebx
imul   %rax,%rbx
shr    $0x23,%rbx
lea    0xda9(%rip),%r14
nopl   (%rax)
mov    %ecx,%eax
cltd
idiv   %ebx
mov    %eax,%ebp
mov    %eax,%esi
shr    $0x3,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%esi
shr    %esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
and    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
cltd
idiv   %ebx
mov    %edx,%ecx
mov    %edx,0x4(%rsp)
movslq %ebx,%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rbx
add    %edx,%ebx
add    $0x9,%eax
cmp    $0x12,%eax
ja     12a0 <main+0x140>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Quersumme zu einer Zahl\0A\00"
@.str.1 = [26 x i8] c"=======================\0A\0A\00"
@.str.2 = [7 x i8] c"Zahl? \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [37 x i8] c"Zahl muss eine Ganzzahl sein.\0AZahl? \00"
@stdin = global i32 0
@.str.5 = [30 x i8] c" Dualdarstellung zu %i: \00"
@.str.6 = [3 x i8] c"%i\00"
@.str.7 = [2 x i8] c" \00"
@.str.8 = [31 x i8] c"\0ADuale BCD-Darstellung zu %i: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %14, %0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32, i32* @stdin
%17 = call i32 @fflush(i32 %16)
br label %10
18: ; preds = %10
%19 = load i32, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %19)
store i32 31, i32* %3
br label %21
21: ; preds = %36, %18
%22 = load i32, i32* %3
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %39
24: ; preds = %21
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = ashr i32 %25, %26
%28 = and i32 %27, 1
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %3
%31 = srem i32 %30, 8
%32 = icmp ne i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %24
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %35
35: ; preds = %33, %24
br label %36
36: ; preds = %35
%37 = load i32, i32* %3
%38 = add nsw i32 %37, -1
store i32 %38, i32* %3
br label %21
39: ; preds = %21
%40 = load i32, i32* %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i32 %40)
store i32 10, i32* %4
br label %42
42: ; preds = %47, %39
%43 = load i32, i32* %2
%44 = load i32, i32* %4
%45 = sdiv i32 %43, %44
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i32, i32* %4
%49 = mul nsw i32 %48, 10
store i32 %49, i32* %4
br label %42
50: ; preds = %42
%51 = load i32, i32* %4
%52 = sdiv i32 %51, 10
store i32 %52, i32* %4
br label %53
53: ; preds = %72, %50
%54 = load i32, i32* %4
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %79
56: ; preds = %53
%57 = load i32, i32* %2
%58 = load i32, i32* %4
%59 = sdiv i32 %57, %58
store i32 %59, i32* %5
store i32 3, i32* %6
br label %60
60: ; preds = %69, %56
%61 = load i32, i32* %6
%62 = icmp sge i32 %61, 0
br i1 %62, label %63, label %72
63: ; preds = %60
%64 = load i32, i32* %5
%65 = load i32, i32* %6
%66 = ashr i32 %64, %65
%67 = and i32 %66, 1
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %63
%70 = load i32, i32* %6
%71 = add nsw i32 %70, -1
store i32 %71, i32* %6
br label %60
72: ; preds = %60
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%74 = load i32, i32* %4
%75 = load i32, i32* %2
%76 = srem i32 %75, %74
store i32 %76, i32* %2
%77 = load i32, i32* %4
%78 = sdiv i32 %77, 10
store i32 %78, i32* %4
br label %53
79: ; preds = %53
%80 = load i32, i32* @stdin
%81 = call i32 @fflush(i32 %80)
%82 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [7 x i8] c"Zahl? \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [37 x i8] c"Zahl muss eine Ganzzahl sein.\0AZahl? \00"
@stdin = global i32 0
@.str.5 = [30 x i8] c" Dualdarstellung zu %i: \00"
@.str.6 = [3 x i8] c"%i\00"
@.str.8 = [31 x i8] c"\0ADuale BCD-Darstellung zu %i: \00"
@str = [24 x i8] c"Quersumme zu einer Zahl\00"
@str.9 = [25 x i8] c"=======================\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.9, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0, %8
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fflush(i32 %10)
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %8, label %14
14: ; preds = %8, %0
%15 = load i32, i32* %1
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %15)
br label %23
17: ; preds = %33
%18 = load i32, i32* %1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %1
%21 = add i32 %20, 9
%22 = icmp ult i32 %21, 19
br i1 %22, label %43, label %36
23: ; preds = %14, %33
%24 = phi i32 [ 31, %14 ], [ %34, %33 ]
%25 = load i32, i32* %1
%26 = lshr i32 %25, %24
%27 = and i32 %26, 1
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%29 = and i32 %24, 7
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 @putchar(i32 32)
br label %33
33: ; preds = %23, %31
%34 = add nsw i32 %24, -1
%35 = icmp eq i32 %24, 0
br i1 %35, label %17, label %23
36: ; preds = %17, %36
%37 = phi i32 [ %38, %36 ], [ 10, %17 ]
%38 = mul nuw nsw i32 %37, 10
%39 = sdiv i32 %20, %38
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %36
41: ; preds = %36
%42 = icmp ult i32 %38, 10
br i1 %42, label %67, label %43
43: ; preds = %17, %41
%44 = phi i32 [ %38, %41 ], [ 10, %17 ]
%45 = udiv i32 %44, 10
br label %46
46: ; preds = %43, %46
%47 = phi i32 [ %63, %46 ], [ %20, %43 ]
%48 = phi i32 [ %64, %46 ], [ %45, %43 ]
%49 = sdiv i32 %47, %48
%50 = lshr i32 %49, 3
%51 = and i32 %50, 1
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %51)
%53 = lshr i32 %49, 2
%54 = and i32 %53, 1
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %54)
%56 = lshr i32 %49, 1
%57 = and i32 %56, 1
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %57)
%59 = and i32 %49, 1
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %59)
%61 = call i32 @putchar(i32 32)
%62 = load i32, i32* %1
%63 = srem i32 %62, %48
store i32 %63, i32* %1
%64 = sdiv i32 %48, 10
%65 = add nsw i32 %48, 9
%66 = icmp ult i32 %65, 19
br i1 %66, label %67, label %46
67: ; preds = %46, %41
%68 = load i32, i32* @stdin
%69 = call i32 @fflush(i32 %68)
%70 = call i32 (...) @getchar()
ret i32 0
}