#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 add_naf(int, int);
int from_naf(int);
int /*<<< orphan*/ printf(char *, int, int, int, ...);
int to_naf(int);
int main() {
  int a = 38094;
  int b = to_naf(a);
  int c = from_naf(b);
  int d = 12345;
  int e = to_naf(d);
  int f = from_naf(e);
  int g = add_naf(b, e);
  int h = from_naf(g);
  printf("%X -> %X -> %X\n", a, b, c);
  printf("%X -> %X -> %X\n", d, e, f);
  printf("%d + %d -> %X + %X = %X -> %d = %d\n", a, d, b, e, g, h, a + d);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x94ce,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <to_naf@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <from_naf@plt>
mov    %eax,-0x10(%rbp)
movl   $0x3039,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <to_naf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <from_naf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <add_naf@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1060 <from_naf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x24(%rbp),%r10d
mov    -0x8(%rbp),%eax
add    -0x14(%rbp),%eax
lea    0xe1e(%rip),%rdi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x94ce,%edi
call   1040 <to_naf@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <from_naf@plt>
mov    %eax,%r12d
mov    $0x3039,%edi
call   1040 <to_naf@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <from_naf@plt>
mov    %eax,%r13d
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <add_naf@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1060 <from_naf@plt>
mov    %rax,(%rsp)
lea    0xe6b(%rip),%r15
mov    %r15,%rdi
mov    $0x94ce,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    $0x3039,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe4c(%rip),%rdi
mov    $0x94ce,%esi
mov    $0x3039,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
push   $0xc507
push   0x8(%rsp)
call   1050 <printf@plt>
add    $0x10,%rsp
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%X -> %X -> %X\0A\00"
@.str.1 = [36 x i8] c"%d + %d -> %X + %X = %X -> %d = %d\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 i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 38094, i32* %2
%10 = load i32, i32* %2
%11 = call i32 @to_naf(i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = call i32 @from_naf(i32 %12)
store i32 %13, i32* %4
store i32 12345, i32* %5
%14 = load i32, i32* %5
%15 = call i32 @to_naf(i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = call i32 @from_naf(i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %3
%19 = load i32, i32* %6
%20 = call i32 @add_naf(i32 %18, i32 %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = call i32 @from_naf(i32 %21)
store i32 %22, i32* %9
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24, i32 %25)
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %28, i32 %29)
%31 = load i32, i32* %2
%32 = load i32, i32* %5
%33 = load i32, i32* %3
%34 = load i32, i32* %6
%35 = load i32, i32* %8
%36 = load i32, i32* %9
%37 = load i32, i32* %2
%38 = load i32, i32* %5
%39 = add nsw i32 %37, %38
%40 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %32, i32 %33, i32 %34, i32 %35, i32 %36, i32 %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"%X -> %X -> %X\0A\00"
@.str.1 = [36 x i8] c"%d + %d -> %X + %X = %X -> %d = %d\0A\00"
define i32 @main() {
%1 = tail call i32 @to_naf(i32 38094)
%2 = tail call i32 @from_naf(i32 %1)
%3 = tail call i32 @to_naf(i32 12345)
%4 = tail call i32 @from_naf(i32 %3)
%5 = tail call i32 @add_naf(i32 %1, i32 %3)
%6 = tail call i32 @from_naf(i32 %5)
%7 = tail call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 38094, i32 %1, i32 %2)
%8 = tail call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 12345, i32 %3, i32 %4)
%9 = tail call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 38094, i32 12345, i32 %1, i32 %3, i32 %5, i32 %6, i32 50439)
ret i32 0
}