#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 /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  const int div_num = 2;
  int n, n2;
  int piliko, ypoloipo;
  char ypol_char;
  printf("give a number\n");
  scanf("%i", &n);
  while (n < 0) {
    printf("lathos! give a number\n");
    scanf("%i", &n);
  }
  n2 = n;
  while (n2 != '0') {
    piliko = n2 / div_num;
    ypoloipo = n2 % div_num;
    ypol_char = (ypoloipo == 0 ? '0' : '1');
    putchar(ypol_char);
    n2 = piliko;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
lea    0xebe(%rip),%rdi
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jge    118d <main+0x5d>
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
lea    0xe81(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1162 <main+0x32>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x30,-0x10(%rbp)
je     11e3 <main+0xb3>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    $0x31,%eax
mov    $0x30,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1193 <main+0x63>
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    0xecd(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb6(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
jns    118b <main+0x5b>
lea    0xea0(%rip),%r14
lea    0xe96(%rip),%r15
lea    0x4(%rsp),%rbx
nop
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
js     1170 <main+0x40>
cmp    $0x30,%ebp
je     11bf <main+0x8f>
mov    %ebp,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
shr    $0x1f,%ebx
add    %ebp,%ebx
sar    %ebx
mov    %ebp,%eax
and    $0x1,%al
or     $0x30,%al
movzbl %al,%edi
call   1030 <putchar@plt>
and    $0xfffffffe,%ebp
cmp    $0x60,%ebp
mov    %ebx,%ebp
jne    11a0 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"give a number\0A\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [23 x i8] c"lathos! give a number\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %1
store i32 2, i32* %2
%8 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %10
16: ; preds = %10
%17 = load i32, i32* %3
store i32 %17, i32* %4
br label %18
18: ; preds = %21, %16
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 48
br i1 %20, label %21, label %34
21: ; preds = %18
%22 = load i32, i32* %4
%23 = sdiv i32 %22, 2
store i32 %23, i32* %5
%24 = load i32, i32* %4
%25 = srem i32 %24, 2
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 48, i32 49
%30 = trunc i32 %29 to i8
store i8 %30, i8* %7
%31 = load i8, i8* %7
%32 = call i32 @putchar(i8 signext %31)
%33 = load i32, i32* %5
store i32 %33, i32* %4
br label %18
34: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%i\00"
@str = [14 x i8] c"give a number\00"
@str.3 = [22 x i8] c"lathos! give a number\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %10, %0
%8 = phi i32 [ %5, %0 ], [ %13, %10 ]
%9 = icmp eq i32 %8, 48
br i1 %9, label %24, label %15
10: ; preds = %0, %10
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.3, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 0
br i1 %14, label %10, label %7
15: ; preds = %7, %15
%16 = phi i32 [ %17, %15 ], [ %8, %7 ]
%17 = sdiv i32 %16, 2
%18 = trunc i32 %16 to i8
%19 = and i8 %18, 1
%20 = or i8 %19, 48
%21 = call i32 @putchar(i8 signext %20)
%22 = and i32 %16, -2
%23 = icmp eq i32 %22, 96
br i1 %23, label %24, label %15
24: ; preds = %15, %7
ret i32 0
}