#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 *, long long *);
int main() {
  long long n;
  long long ara[5000], i;
  while (scanf("%lld", &n) == 1) {
    if (n == 0)
      printf("0\n");
    else if (n < 0)
      break;
    else {
      for (i = 0; n > 0; i++) {
        ara[i] = n % 3;
        n = n / 3;
      }
      for (i = i - 1; i >= 0; i--)
        printf("%lld", ara[i]);
      printf("\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    1241 <main+0x121>
cmpq   $0x0,-0x10(%rbp)
jne    1169 <main+0x49>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123c <main+0x11c>
cmpq   $0x0,-0x10(%rbp)
jge    1179 <main+0x59>
jmp    1241 <main+0x121>
movq   $0x0,-0x9c58(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    11d5 <main+0xb5>
mov    -0x10(%rbp),%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    -0x9c58(%rbp),%rax
mov    %rdx,-0x9c50(%rbp,%rax,8)
ff
mov    -0x10(%rbp),%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x9c58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x9c58(%rbp)
jmp    1184 <main+0x64>
mov    -0x9c58(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x9c58(%rbp)
cmpq   $0x0,-0x9c58(%rbp)
jl     1229 <main+0x109>
mov    -0x9c58(%rbp),%rax
mov    -0x9c50(%rbp,%rax,8),%rsi
ff
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x9c58(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x9c58(%rbp)
jmp    11e7 <main+0xc7>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123c <main+0x11c>
jmp    1132 <main+0x12>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9c50,%rsp
lea    0xea9(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1227 <main+0xe7>
lea    0xe94(%rip),%r14
lea    0xe88(%rip),%r13
lea    0x8(%rsp),%r15
movabs $0xaaaaaaaaaaaaaaab,%r12
aa aa aa
jmp    11a8 <main+0x68>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1227 <main+0xe7>
mov    0x8(%rsp),%rdx
test   %rdx,%rdx
je     1190 <main+0x50>
js     1227 <main+0xe7>
mov    $0x2,%edi
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
mov    %rdx,%rcx
mov    %rdx,%rax
mul    %r12
mov    %rdi,%rbx
shr    %rdx
lea    (%rdx,%rdx,2),%rax
mov    %rcx,%rdi
sub    %rax,%rdi
mov    %rdi,0x10(%rsp,%rsi,8)
add    $0x1,%rsi
lea    0x1(%rbx),%rdi
cmp    $0x3,%rcx
jae    11c0 <main+0x80>
mov    %rdx,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,8),%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1200 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1198 <main+0x58>
xor    %eax,%eax
add    $0x9c50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
@str = [2 x i8] c"0\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [5000 x i64]
%3 = bitcast i64* %1 to i8*
%4 = bitcast [5000 x i64]* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %35
7: ; preds = %0, %32
%8 = load i64, i64* %1
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %32
12: ; preds = %7
%13 = icmp slt i64 %8, 0
br i1 %13, label %35, label %15
14: ; preds = %15
store i64 %20, i64* %1
br label %23
15: ; preds = %12, %15
%16 = phi i64 [ %21, %15 ], [ 0, %12 ]
%17 = phi i64 [ %20, %15 ], [ %8, %12 ]
%18 = urem i64 %17, 3
%19 = getelementptr inbounds [5000 x i64], [5000 x i64]* %2, i64 0, i64 %16
store i64 %18, i64* %19
%20 = udiv i64 %17, 3
%21 = add nuw nsw i64 %16, 1
%22 = icmp ult i64 %17, 3
br i1 %22, label %14, label %15
23: ; preds = %14, %23
%24 = phi i64 [ %25, %23 ], [ %21, %14 ]
%25 = add nsw i64 %24, -1
%26 = getelementptr inbounds [5000 x i64], [5000 x i64]* %2, i64 0, i64 %25
%27 = load i64, i64* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %27)
%29 = icmp ugt i64 %24, 1
br i1 %29, label %23, label %30
30: ; preds = %23
%31 = call i32 @putchar(i32 10)
br label %32
32: ; preds = %30, %10
%33 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%34 = icmp eq i32 %33, 1
br i1 %34, label %7, label %35
35: ; preds = %32, %12, %0
ret i32 0
}