#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 *, unsigned int *);
int /*<<< orphan*/ stdin;
int main(void) {
  unsigned int zahl, outzahl, quersumme = 0;
  printf("Quersumme zu einer Zahl\n");
  printf("=======================\n\n");
  printf("Zahl? ");
  while (!scanf("%u", &zahl)) {
    printf("Zahl muss eine positive Ganzzahl sein.\nZahl? ");
    fflush(stdin);
  }
  outzahl = zahl;
  quersumme += zahl % 10;
  while (zahl = zahl / 10)
    quersumme += zahl % 10;
  printf("Quersumme zu %u ist: %u", outzahl, quersumme);
  fflush(stdin);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeef(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a5 <main+0x65>
jmp    11c6 <main+0x86>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    1180 <main+0x40>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    -0x10(%rbp),%edx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     120d <main+0xcd>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    -0x10(%rbp),%edx
mov    %edx,-0x10(%rbp)
jmp    11de <main+0x9e>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xee7(%rip),%rdi
call   1030 <puts@plt>
lea    0xef3(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebe(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
test   %eax,%eax
jne    11d2 <main+0x82>
lea    0xe66(%rip),%r14
mov    0x2e47(%rip),%r12
lea    0xe9b(%rip),%r15
lea    0x4(%rsp),%rbx
nopl   (%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%edi
call   1060 <fflush@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
test   %eax,%eax
je     11b0 <main+0x60>
mov    0x4(%rsp),%esi
mov    $0xcccccccd,%r8d
mov    %rsi,%rcx
imul   %r8,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edi
mov    %esi,%edx
sub    %edi,%edx
cmp    $0xa,%rsi
jae    1200 <main+0xb0>
mov    %ecx,%edi
jmp    121d <main+0xcd>
nopl   0x0(%rax,%rax,1)
mov    %ecx,%edi
imul   %r8,%rdi
shr    $0x23,%rdi
lea    (%rdi,%rdi,1),%ebx
lea    (%rbx,%rbx,4),%ebx
mov    %ecx,%eax
sub    %ebx,%eax
add    %eax,%edx
cmp    $0x9,%ecx
mov    %edi,%ecx
ja     1200 <main+0xb0>
mov    %edi,0x4(%rsp)
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2db2(%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    %r14
pop    %r15
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"%u\00"
@.str.4 = [46 x i8] c"Zahl muss eine positive Ganzzahl sein.\0AZahl? \00"
@stdin = global i32 0
@.str.5 = [24 x i8] c"Quersumme zu %u ist: %u\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %12, %0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%14 = load i32, i32* @stdin
%15 = call i32 @fflush(i32 %14)
br label %8
16: ; preds = %8
%17 = load i32, i32* %2
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = urem i32 %18, 10
%20 = load i32, i32* %4
%21 = add i32 %20, %19
store i32 %21, i32* %4
br label %22
22: ; preds = %26, %16
%23 = load i32, i32* %2
%24 = udiv i32 %23, 10
store i32 %24, i32* %2
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* %2
%28 = urem i32 %27, 10
%29 = load i32, i32* %4
%30 = add i32 %29, %28
store i32 %30, i32* %4
br label %22
31: ; preds = %22
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %32, i32 %33)
%35 = load i32, i32* @stdin
%36 = call i32 @fflush(i32 %35)
%37 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [7 x i8] c"Zahl? \00"
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [46 x i8] c"Zahl muss eine positive Ganzzahl sein.\0AZahl? \00"
@stdin = global i32 0
@.str.5 = [24 x i8] c"Quersumme zu %u ist: %u\00"
@str = [24 x i8] c"Quersumme zu einer Zahl\00"
@str.6 = [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.6, 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 ([46 x i8], [46 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 = urem i32 %15, 10
%17 = udiv i32 %15, 10
%18 = icmp ult i32 %15, 10
br i1 %18, label %26, label %19
19: ; preds = %14, %19
%20 = phi i32 [ %24, %19 ], [ %17, %14 ]
%21 = phi i32 [ %23, %19 ], [ %16, %14 ]
%22 = urem i32 %20, 10
%23 = add i32 %22, %21
%24 = udiv i32 %20, 10
%25 = icmp ult i32 %20, 10
br i1 %25, label %26, label %19
26: ; preds = %19, %14
%27 = phi i32 [ %17, %14 ], [ %24, %19 ]
%28 = phi i32 [ %16, %14 ], [ %23, %19 ]
store i32 %27, i32* %1
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %15, i32 %28)
%30 = load i32, i32* @stdin
%31 = call i32 @fflush(i32 %30)
%32 = call i32 (...) @getchar()
ret i32 0
}