#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 *, ...);
int main(void) {
  int i, z;
  i = 0;
  z = 0;
  printf("\nUmwandlung einer Dezimalzahl in eine Binärzahl\n\n");
  do {
    printf("Bitte die gewünschte Länge der Binärzahl eingeben: ");
    if (scanf("%d", &i) > 0) {
      if (i <= 0)
        printf("\nEine negative Länge (%d) ist nicht definiert!\n\n", i);
    } else {
      printf("\nSie haben keine Zahl eingegeben!\n\n");
      scanf("%*s");
    }
  } while (i <= 0);
  if (i > 32) {
    i = 32;
    printf("\nDie Bitlänge ist auf %d Bit begrenzt und wurde auf %d Bit "
           "angepasst!\n",
           i, i);
  }
  do {
    printf("\nBitte die Dezimalzahl eingeben: ");
    if (scanf("%d", &z) < 1) {
      printf("\nSie haben keine Zahl eingegeben!\n");
      scanf("%*s");
    }
  } while (z == 0);
  printf("\n%d ist in %d-Bit Binärdarstellung:\n\n", z, i);
  i--;
  while (i >= 0) {
    if (z & (1 << i))
      printf("1");
    else
      printf("0");
    i--;
  }
  printf("\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0a(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmp    $0x0,%eax
jle    1194 <main+0x74>
cmpl   $0x0,-0x8(%rbp)
jg     118f <main+0x6f>
mov    -0x8(%rbp),%esi
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b0 <main+0x90>
lea    0xf04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf1a(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    11b5 <main+0x95>
cmpl   $0x0,-0x8(%rbp)
jle    114b <main+0x2b>
cmpl   $0x20,-0x8(%rbp)
jle    11e4 <main+0xc4>
movl   $0x20,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e9 <main+0xc9>
lea    0xf1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6c(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmp    $0x1,%eax
jge    122e <main+0x10e>
lea    0xf18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    1233 <main+0x113>
cmpl   $0x0,-0xc(%rbp)
je     11e9 <main+0xc9>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xf0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     12ad <main+0x18d>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1291 <main+0x171>
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129f <main+0x17f>
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    125a <main+0x13a>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xfa0(%rip),%rdi
call   1040 <puts@plt>
lea    0xe93(%rip),%r14
lea    0xec3(%rip),%r15
mov    %rsp,%rbx
lea    0xebc(%rip),%r12
lea    0xfae(%rip),%r13
lea    0xee0(%rip),%rbp
jmp    11a9 <main+0x69>
xchg   %ax,%ax
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    (%rsp),%esi
test   %esi,%esi
jg     11d7 <main+0x97>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
test   %eax,%eax
jle    1190 <main+0x50>
mov    (%rsp),%esi
test   %esi,%esi
jg     11d7 <main+0x97>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a2 <main+0x62>
cmp    $0x21,%esi
jb     11fb <main+0xbb>
movl   $0x20,(%rsp)
lea    0xe86(%rip),%rdi
mov    $0x20,%esi
mov    $0x20,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb6(%rip),%r14
lea    0xe2e(%rip),%rbp
lea    0x4(%rsp),%rbx
lea    0xf41(%rip),%r15
lea    0xe50(%rip),%r12
jmp    1228 <main+0xe8>
xchg   %ax,%ax
mov    0x4(%rsp),%esi
test   %esi,%esi
jne    1257 <main+0x117>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
test   %eax,%eax
jg     1220 <main+0xe0>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
jmp    1220 <main+0xe0>
mov    (%rsp),%edx
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%ecx
lea    -0x1(%rcx),%eax
mov    %eax,(%rsp)
test   %ecx,%ecx
jle    1293 <main+0x153>
mov    0x4(%rsp),%ecx
bt     %eax,%ecx
mov    $0x31,%edi
adc    $0xffffffff,%edi
call   1030 <putchar@plt>
jmp    1270 <main+0x130>
lea    0xdd0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"\0AUmwandlung einer Dezimalzahl in eine Bin\C3\A4rzahl\0A\0A\00"
@.str.1 = [55 x i8] c"Bitte die gew\C3\BCnschte L\C3\A4nge der Bin\C3\A4rzahl eingeben: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [50 x i8] c"\0AEine negative L\C3\A4nge (%d) ist nicht definiert!\0A\0A\00"
@.str.4 = [36 x i8] c"\0ASie haben keine Zahl eingegeben!\0A\0A\00"
@.str.5 = [4 x i8] c"%*s\00"
@.str.6 = [72 x i8] c"\0ADie Bitl\C3\A4nge ist auf %d Bit begrenzt und wurde auf %d Bit angepasst!\0A\00"
@.str.7 = [34 x i8] c"\0ABitte die Dezimalzahl eingeben: \00"
@.str.8 = [35 x i8] c"\0ASie haben keine Zahl eingegeben!\0A\00"
@.str.9 = [39 x i8] c"\0A%d ist in %d-Bit Bin\C3\A4rdarstellung:\0A\0A\00"
@.str.10 = [2 x i8] c"1\00"
@.str.11 = [2 x i8] c"0\00"
@.str.12 = [3 x i8] c"\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %20, %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = load i32, i32* %2
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %12, %9
br label %19
16: ; preds = %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %19
19: ; preds = %16, %15
br label %20
20: ; preds = %19
%21 = load i32, i32* %2
%22 = icmp sle i32 %21, 0
br i1 %22, label %5, label %23
23: ; preds = %20
%24 = load i32, i32* %2
%25 = icmp sgt i32 %24, 32
br i1 %25, label %26, label %30
26: ; preds = %23
store i32 32, i32* %2
%27 = load i32, i32* %2
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.6, i64 0, i64 0), i32 %27, i32 %28)
br label %30
30: ; preds = %26, %23
br label %31
31: ; preds = %39, %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%34 = icmp slt i32 %33, 1
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %35, %31
br label %39
39: ; preds = %38
%40 = load i32, i32* %3
%41 = icmp eq i32 %40, 0
br i1 %41, label %31, label %42
42: ; preds = %39
%43 = load i32, i32* %3
%44 = load i32, i32* %2
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i32 %43, i32 %44)
%46 = load i32, i32* %2
%47 = add nsw i32 %46, -1
store i32 %47, i32* %2
br label %48
48: ; preds = %61, %42
%49 = load i32, i32* %2
%50 = icmp sge i32 %49, 0
br i1 %50, label %51, label %64
51: ; preds = %48
%52 = load i32, i32* %3
%53 = load i32, i32* %2
%54 = shl i32 1, %53
%55 = and i32 %52, %54
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %61
59: ; preds = %51
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %61
61: ; preds = %59, %57
%62 = load i32, i32* %2
%63 = add nsw i32 %62, -1
store i32 %63, i32* %2
br label %48
64: ; preds = %48
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [55 x i8] c"Bitte die gew\C3\BCnschte L\C3\A4nge der Bin\C3\A4rzahl eingeben: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [50 x i8] c"\0AEine negative L\C3\A4nge (%d) ist nicht definiert!\0A\0A\00"
@.str.5 = [4 x i8] c"%*s\00"
@.str.6 = [72 x i8] c"\0ADie Bitl\C3\A4nge ist auf %d Bit begrenzt und wurde auf %d Bit angepasst!\0A\00"
@.str.7 = [34 x i8] c"\0ABitte die Dezimalzahl eingeben: \00"
@.str.9 = [39 x i8] c"\0A%d ist in %d-Bit Bin\C3\A4rdarstellung:\0A\0A\00"
@str = [50 x i8] c"\0AUmwandlung einer Dezimalzahl in eine Bin\C3\A4rzahl\0A\00"
@str.13 = [35 x i8] c"\0ASie haben keine Zahl eingegeben!\0A\00"
@str.14 = [2 x i8] c"\0A\00"
@str.15 = [34 x i8] c"\0ASie haben keine Zahl eingegeben!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %1
store i32 0, i32* %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %18, %0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %11)
br label %18
15: ; preds = %6
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.13, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %18
18: ; preds = %15, %13
%19 = load i32, i32* %1
%20 = icmp slt i32 %19, 1
br i1 %20, label %6, label %21
21: ; preds = %10, %18
%22 = phi i32 [ %19, %18 ], [ %11, %10 ]
%23 = icmp ugt i32 %22, 32
br i1 %23, label %24, label %26
24: ; preds = %21
store i32 32, i32* %1
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.6, i64 0, i64 0), i32 32, i32 32)
br label %26
26: ; preds = %24, %21
br label %27
27: ; preds = %26, %34
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%30 = icmp slt i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.15, i64 0, i64 0))
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %27, %31
%35 = load i32, i32* %2
%36 = icmp eq i32 %35, 0
br i1 %36, label %27, label %37
37: ; preds = %34
%38 = load i32, i32* %1
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i32 %35, i32 %38)
%40 = load i32, i32* %1
%41 = add nsw i32 %40, -1
store i32 %41, i32* %1
%42 = icmp sgt i32 %40, 0
br i1 %42, label %43, label %54
43: ; preds = %37, %43
%44 = phi i32 [ %52, %43 ], [ %41, %37 ]
%45 = load i32, i32* %2
%46 = shl nuw i32 1, %44
%47 = and i32 %45, %46
%48 = icmp eq i32 %47, 0
%49 = select i1 %48, i32 48, i32 49
%50 = call i32 @putchar(i32 %49)
%51 = load i32, i32* %1
%52 = add nsw i32 %51, -1
store i32 %52, i32* %1
%53 = icmp sgt i32 %51, 0
br i1 %53, label %43, label %54
54: ; preds = %43, %37
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.14, i64 0, i64 0))
ret i32 0
}