#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);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int n = (int)strtol(argv[1], NULL, 10);
  while (n != 1) {
    switch (n % 3) {
    case 0:
      printf("%d 0\n", n);
      break;
    case 1:
      printf("%d -1\n", n--);
      break;
    case 2:
      printf("%d +1\n", n++);
    }
    n /= 3;
  }
  printf("%d", n);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     1204 <main+0xe4>
movslq -0x14(%rbp),%rcx
mov    %ecx,%eax
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
je     11aa <main+0x8a>
jmp    1188 <main+0x68>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     11be <main+0x9e>
jmp    1199 <main+0x79>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
je     11da <main+0xba>
jmp    11f1 <main+0xd1>
mov    -0x14(%rbp),%esi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
jmp    11f1 <main+0xd1>
mov    -0x14(%rbp),%esi
mov    %esi,%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
jmp    11f1 <main+0xd1>
mov    -0x14(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    114f <main+0x2f>
mov    -0x14(%rbp),%esi
lea    0xe06(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rsi
cmp    $0x1,%esi
jne    115d <main+0x3d>
lea    0xece(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe9c(%rip),%rbx
lea    0xea2(%rip),%r14
lea    0xe94(%rip),%r15
jmp    11ac <main+0x8c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(%rsi),%ebp
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %ebp,%esi
movslq %esi,%rax
imul   $0x55555556,%rax,%rsi
mov    %rsi,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rsi
add    %ecx,%esi
add    $0xfffffffd,%eax
cmp    $0x2,%eax
jbe    113f <main+0x1f>
movslq %esi,%rax
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
mov    %rbx,%rdi
mov    %esi,%ebp
sub    %ecx,%eax
je     1186 <main+0x66>
cmp    $0x2,%eax
je     1180 <main+0x60>
cmp    $0x1,%eax
jne    118d <main+0x6d>
lea    -0x1(%rsi),%ebp
mov    %r15,%rdi
jmp    1186 <main+0x66>

LLVM IR (-O0):
@.str = [6 x i8] c"%d 0\0A\00"
@.str.1 = [7 x i8] c"%d -1\0A\00"
@.str.2 = [7 x i8] c"%d +1\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = call i64 @strtol(i8* %9, i32* null, i32 10)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %6
br label %12
12: ; preds = %29, %2
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %32
15: ; preds = %12
%16 = load i32, i32* %6
%17 = srem i32 %16, 3
switch i32 %17, label %29 [
i32 0, label %18
i32 1, label %21
i32 2, label %25
]
18: ; preds = %15
%19 = load i32, i32* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %29
21: ; preds = %15
%22 = load i32, i32* %6
%23 = add nsw i32 %22, -1
store i32 %23, i32* %6
%24 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %29
25: ; preds = %15
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %29
29: ; preds = %25, %15, %21, %18
%30 = load i32, i32* %6
%31 = sdiv i32 %30, 3
store i32 %31, i32* %6
br label %12
32: ; preds = %12
%33 = load i32, i32* %6
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d 0\0A\00"
@.str.1 = [7 x i8] c"%d -1\0A\00"
@.str.2 = [7 x i8] c"%d +1\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i64 @strtol(i8* nocapture %4, i32* null, i32 10)
%6 = trunc i64 %5 to i32
%7 = icmp eq i32 %6, 1
br i1 %7, label %24, label %8
8: ; preds = %2, %19
%9 = phi i32 [ %21, %19 ], [ %6, %2 ]
%10 = srem i32 %9, 3
switch i32 %10, label %19 [
i32 0, label %15
i32 1, label %11
i32 2, label %13
]
11: ; preds = %8
%12 = add nsw i32 %9, -1
br label %15
13: ; preds = %8
%14 = add nsw i32 %9, 1
br label %15
15: ; preds = %8, %11, %13
%16 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %11 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %8 ]
%17 = phi i32 [ %14, %13 ], [ %12, %11 ], [ %9, %8 ]
%18 = tail call i32 @printf(i8* %16, i32 %9)
br label %19
19: ; preds = %15, %8
%20 = phi i32 [ %9, %8 ], [ %17, %15 ]
%21 = sdiv i32 %20, 3
%22 = add i32 %20, -3
%23 = icmp ult i32 %22, 3
br i1 %23, label %24, label %8
24: ; preds = %19, %2
%25 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 1)
ret i32 0
}