#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdout;
int main() {
  int usrInput;
  fprintf(stdout, "Angka: ");
  scanf("%d", &usrInput);
  int *binary = (int *)malloc(sizeof(int) * 256);
  int index = 0;
  for (; usrInput > 0; usrInput /= 2, index++) {
    binary[index] = usrInput & 1;
    printf("-%d-%d-\n", index, binary[index]);
  }
  for (index -= 1; index >= 0; index--)
    printf("%d", binary[index]);
  puts("");
  free(binary);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe7d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11fc <main+0x9c>
mov    -0x8(%rbp),%edx
and    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a9 <main+0x49>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1236 <main+0xd6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1205 <main+0xa5>
lea    0xdd6(%rip),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe83(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    120b <main+0xab>
lea    0xe60(%rip),%r15
xor    %ebx,%ebx
nopl   (%rax)
and    $0x1,%edx
mov    %edx,(%r14,%rbx,4)
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
mov    %edx,0xc(%rsp)
add    $0x1,%rbx
cmp    $0x1,%eax
jg     11b0 <main+0x50>
test   %ebx,%ebx
jle    120b <main+0xab>
mov    %ebx,%ebx
add    $0x1,%rbx
lea    0xe1a(%rip),%r15
xchg   %ax,%ax
lea    -0x2(%rbx),%eax
mov    (%r14,%rax,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11f0 <main+0x90>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [8 x i8] c"Angka: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"-%d-%d-\0A\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @stdout
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = call i64 @malloc(i32 1024)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %3
store i32 0, i32* %4
br label %10
10: ; preds = %27, %0
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %10
%14 = load i32, i32* %2
%15 = and i32 %14, 1
%16 = load i32*, i32** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
store i32 %15, i32* %19
%20 = load i32, i32* %4
%21 = load i32*, i32** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %25)
br label %27
27: ; preds = %13
%28 = load i32, i32* %2
%29 = sdiv i32 %28, 2
store i32 %29, i32* %2
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %10
32: ; preds = %10
%33 = load i32, i32* %4
%34 = sub nsw i32 %33, 1
store i32 %34, i32* %4
br label %35
35: ; preds = %45, %32
%36 = load i32, i32* %4
%37 = icmp sge i32 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i32*, i32** %3
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %38
%46 = load i32, i32* %4
%47 = add nsw i32 %46, -1
store i32 %47, i32* %4
br label %35
48: ; preds = %35
%49 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32*, i32** %3
%51 = call i32 @free(i32* %50)
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [8 x i8] c"Angka: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"-%d-%d-\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @stdout
%4 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = call i64 @malloc(i32 1024)
%7 = inttoptr i64 %6 to i32*
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %15, label %34
10: ; preds = %15
%11 = trunc i64 %24 to i32
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %10
%14 = and i64 %24, 4294967295
br label %26
15: ; preds = %0, %15
%16 = phi i64 [ %24, %15 ], [ 0, %0 ]
%17 = phi i32 [ %23, %15 ], [ %8, %0 ]
%18 = and i32 %17, 1
%19 = getelementptr inbounds i32, i32* %7, i64 %16
store i32 %18, i32* %19
%20 = trunc i64 %16 to i32
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %18)
%22 = load i32, i32* %1
%23 = sdiv i32 %22, 2
store i32 %23, i32* %1
%24 = add nuw i64 %16, 1
%25 = icmp sgt i32 %22, 1
br i1 %25, label %15, label %10
26: ; preds = %13, %26
%27 = phi i64 [ %14, %13 ], [ %28, %26 ]
%28 = add nsw i64 %27, -1
%29 = and i64 %28, 4294967295
%30 = getelementptr inbounds i32, i32* %7, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = icmp ugt i64 %27, 1
br i1 %33, label %26, label %34
34: ; preds = %26, %0, %10
%35 = call i32 @putchar(i32 10)
%36 = call i32 @free(i32* %7)
ret i32 0
}