#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*/ scanf(char *, int *);
int main() {
  int num;
  printf("Enter number: ");
  scanf("%d", &num);
  while (num != 1) {
    if (num % 3 == 0) {
      printf("%d 0\n", num);
      num /= 3;
    } else if (num % 3 == 1) {
      printf("%d -1\n", num);
      num--;
      num /= 3;
    } else if (num % 3 == 2) {
      printf("%d 1\n", num);
      num++;
      num /= 3;
    }
  }
  printf("1\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
je     121b <main+0xfb>
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118f <main+0x6f>
mov    -0x8(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1216 <main+0xf6>
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    11d0 <main+0xb0>
mov    -0x8(%rbp),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1211 <main+0xf1>
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x2,%edx
jne    120c <main+0xec>
mov    -0x8(%rbp),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1211 <main+0xf1>
jmp    1216 <main+0xf6>
jmp    114d <main+0x2d>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
cmp    $0x1,%esi
jne    1179 <main+0x49>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe9f(%rip),%r14
lea    0xe91(%rip),%rbx
lea    0xe84(%rip),%r15
jmp    11c0 <main+0x90>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cltq
imul   $0x55555556,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
shr    $0x20,%rsi
add    %eax,%esi
mov    %esi,0xc(%rsp)
cmp    $0x1,%esi
je     1161 <main+0x31>
movslq %esi,%rax
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cmp    $0x2,%eax
je     1200 <main+0xd0>
cmp    $0x1,%eax
je     1190 <main+0x60>
test   %eax,%eax
jne    11bb <main+0x8b>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0xc(%rsp),%rax
jmp    11a3 <main+0x73>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
add    $0x1,%eax
jmp    11a1 <main+0x71>

LLVM IR (-O0):
@.str = [15 x i8] c"Enter number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"%d 0\0A\00"
@.str.3 = [7 x i8] c"%d -1\0A\00"
@.str.4 = [6 x i8] c"%d 1\0A\00"
@.str.5 = [3 x i8] c"1\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 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* %2)
br label %5
5: ; preds = %41, %0
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 1
br i1 %7, label %8, label %42
8: ; preds = %5
%9 = load i32, i32* %2
%10 = srem i32 %9, 3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 3
store i32 %16, i32* %2
br label %41
17: ; preds = %8
%18 = load i32, i32* %2
%19 = srem i32 %18, 3
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %2
%25 = add nsw i32 %24, -1
store i32 %25, i32* %2
%26 = load i32, i32* %2
%27 = sdiv i32 %26, 3
store i32 %27, i32* %2
br label %40
28: ; preds = %17
%29 = load i32, i32* %2
%30 = srem i32 %29, 3
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i32, i32* %2
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
%37 = load i32, i32* %2
%38 = sdiv i32 %37, 3
store i32 %38, i32* %2
br label %39
39: ; preds = %32, %28
br label %40
40: ; preds = %39, %21
br label %41
41: ; preds = %40, %12
br label %5
42: ; preds = %5
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"%d 0\0A\00"
@.str.3 = [7 x i8] c"%d -1\0A\00"
@.str.4 = [6 x i8] c"%d 1\0A\00"
@str = [2 x i8] c"1\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 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 eq i32 %5, 1
br i1 %6, label %27, label %7
7: ; preds = %0, %24
%8 = phi i32 [ %25, %24 ], [ %5, %0 ]
%9 = srem i32 %8, 3
switch i32 %9, label %24 [
i32 0, label %10
i32 1, label %14
i32 2, label %19
]
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%12 = load i32, i32* %1
%13 = sdiv i32 %12, 3
store i32 %13, i32* %1
br label %24
14: ; preds = %7
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%16 = load i32, i32* %1
%17 = add nsw i32 %16, -1
%18 = sdiv i32 %17, 3
store i32 %18, i32* %1
br label %24
19: ; preds = %7
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%21 = load i32, i32* %1
%22 = add nsw i32 %21, 1
%23 = sdiv i32 %22, 3
store i32 %23, i32* %1
br label %24
24: ; preds = %7, %14, %19, %10
%25 = phi i32 [ %8, %7 ], [ %18, %14 ], [ %23, %19 ], [ %13, %10 ]
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %7
27: ; preds = %24, %0
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret i32 0
}