#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 */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, long *);
int main() {
  long int a, b = 0, c, ara[200], i;
  double ans = 0;
  while (scanf("%ld", &a) != EOF) {
    if (a == 0) {
      printf("%.0lf\n", ans);
      continue;
    }
    if (a < 0)
      break;
    for (i = 0; a != 0; i++) {
      ara[i] = a % 3;
      a /= 3;
    }
    for (b = i - 1; b >= 0; b--) {
      printf("%ld", ara[b]);
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x670,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x670(%rbp)
ff
lea    0xeb4(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    0x2e8c(%rip),%rcx
cmp    (%rcx),%rax
je     124f <main+0x12f>
cmpq   $0x0,-0x10(%rbp)
jne    118b <main+0x6b>
movsd  -0x670(%rbp),%xmm0
ff
lea    0xe85(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1145 <main+0x25>
cmpq   $0x0,-0x10(%rbp)
jge    119b <main+0x7b>
jmp    124f <main+0x12f>
movq   $0x0,-0x668(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f7 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    -0x668(%rbp),%rax
mov    %rdx,-0x660(%rbp,%rax,8)
ff
mov    -0x10(%rbp),%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x668(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x668(%rbp)
jmp    11a6 <main+0x86>
mov    -0x668(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jl     123c <main+0x11c>
mov    -0x18(%rbp),%rax
mov    -0x660(%rbp,%rax,8),%rsi
ff
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1206 <main+0xe6>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1145 <main+0x25>
xor    %eax,%eax
add    $0x670,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x658,%rsp
lea    0xeb8(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x2e8f(%rip),%r12
cmp    (%r12),%rax
jne    1173 <main+0x43>
xor    %eax,%eax
add    $0x658,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe86(%rip),%r13
lea    0x8(%rsp),%r15
movabs $0x5555555555555556,%rbx
55 55 55
jmp    11b2 <main+0x82>
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
lea    0xe6a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
cmp    (%r12),%rax
je     115f <main+0x2f>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1190 <main+0x60>
js     115f <main+0x2f>
mov    $0xffffffffffffffff,%r14
mov    $0x1,%edx
nopw   0x0(%rax,%rax,1)
mov    %rax,%rcx
mov    %rdx,%rbp
imul   %rbx
mov    %rdx,%rax
shr    $0x3f,%rax
add    %rdx,%rax
lea    (%rax,%rax,2),%rdx
mov    %rcx,%rsi
sub    %rdx,%rsi
mov    %rsi,0x18(%rsp,%r14,8)
add    $0x2,%rcx
add    $0x1,%r14
lea    0x1(%rbp),%rdx
cmp    $0x5,%rcx
jae    11d0 <main+0xa0>
mov    %rax,0x8(%rsp)
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14,%r14
je     1238 <main+0x108>
nopl   0x0(%rax,%rax,1)
mov    (%rsp,%rbp,8),%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
jg     1220 <main+0xf0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11a1 <main+0x71>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
@EOF = global i64 0
@.str.1 = [7 x i8] c"%.0lf\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [200 x i64]
%3 = bitcast i64* %1 to i8*
%4 = bitcast [200 x i64]* %2 to i8*
%5 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %40, label %8
8: ; preds = %0, %13
%9 = load i64, i64* %1
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double 0.000000e+00)
br label %13
13: ; preds = %11, %38
%14 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %40, label %8
17: ; preds = %8
%18 = icmp slt i64 %9, 0
br i1 %18, label %40, label %22
19: ; preds = %22
store i64 %27, i64* %1
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %25)
%21 = icmp eq i64 %23, 0
br i1 %21, label %38, label %31
22: ; preds = %17, %22
%23 = phi i64 [ %28, %22 ], [ 0, %17 ]
%24 = phi i64 [ %27, %22 ], [ %9, %17 ]
%25 = srem i64 %24, 3
%26 = getelementptr inbounds [200 x i64], [200 x i64]* %2, i64 0, i64 %23
store i64 %25, i64* %26
%27 = sdiv i64 %24, 3
%28 = add nuw nsw i64 %23, 1
%29 = add i64 %24, 2
%30 = icmp ult i64 %29, 5
br i1 %30, label %19, label %22
31: ; preds = %19, %31
%32 = phi i64 [ %33, %31 ], [ %23, %19 ]
%33 = add nsw i64 %32, -1
%34 = getelementptr inbounds [200 x i64], [200 x i64]* %2, i64 0, i64 %33
%35 = load i64, i64* %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %35)
%37 = icmp sgt i64 %32, 1
br i1 %37, label %31, label %38
38: ; preds = %31, %19
%39 = call i32 @putchar(i32 10)
br label %13
40: ; preds = %13, %17, %0
ret i32 0
}