#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, int);
int scanf(char *, long *, long *, int *);
int main(int argc, char *argv[]) {
  long a, b;
  int d;
  if (scanf("%ld%ld%d", &a, &b, &d) != 3)
    return EXIT_FAILURE;
  long sum = a + b;
  int sum_d[31] = {0};
  int count = 0;
  if (sum == 0) {
    count++;
  } else {
    while (sum) {
      sum_d[count] = sum % d;
      sum /= d;
      count++;
    }
  }
  for (int i = count - 1; i >= 0; i--) {
    printf("%d", sum_d[i]);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb0(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1050 <scanf@plt>
cmp    $0x3,%eax
je     117b <main+0x4b>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1270 <main+0x140>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x7c,%edx
call   1040 <memset@plt>
movl   $0x0,-0xb4(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c3 <main+0x93>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    121a <main+0xea>
jmp    11c8 <main+0x98>
cmpq   $0x0,-0x30(%rbp)
je     1215 <main+0xe5>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
cqto
idiv   %rcx
mov    %edx,%ecx
movslq -0xb4(%rbp),%rax
mov    %ecx,-0xb0(%rbp,%rax,4)
movslq -0x24(%rbp),%rcx
mov    -0x30(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    11c8 <main+0x98>
jmp    121a <main+0xea>
mov    -0xb4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xb8(%rbp)
cmpl   $0x0,-0xb8(%rbp)
jl     1264 <main+0x134>
movslq -0xb8(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%esi
lea    0xdbb(%rip),%rdi
call   1030 <printf@plt>
mov    -0xb8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xb8(%rbp)
jmp    1229 <main+0xf9>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
lea    0xece(%rip),%rdi
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1040 <scanf@plt>
cmp    $0x3,%eax
jne    11c4 <main+0xa4>
mov    0x10(%rsp),%rax
xorps  %xmm0,%xmm0
movups %xmm0,0x8c(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
add    0x18(%rsp),%rax
je     11d1 <main+0xb1>
movslq 0xc(%rsp),%rsi
xor    %ecx,%ecx
jmp    11b2 <main+0x92>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cqto
idiv   %rsi
mov    %edx,0x20(%rsp,%rcx,4)
add    $0x1,%rcx
test   %rax,%rax
je     11cd <main+0xad>
mov    %rax,%rdx
or     %rsi,%rdx
shr    $0x20,%rdx
jne    11a0 <main+0x80>
xor    %edx,%edx
div    %esi
jmp    11a5 <main+0x85>
mov    0x2e15(%rip),%rax
jmp    120d <main+0xed>
mov    %ecx,%eax
jmp    11d6 <main+0xb6>
mov    $0x1,%eax
lea    0x1(%rax),%ebp
add    $0xffffffff,%eax
lea    (%rsp,%rax,4),%rbx
add    $0x20,%rbx
lea    0xe1b(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
add    $0xfffffffffffffffc,%rbx
cmp    $0x1,%ebp
jg     11f0 <main+0xd0>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%ld%ld%d\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca [31 x i32]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64* %6, i64* %7, i32* %8)
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %64
17: ; preds = %2
%18 = load i64, i64* %6
%19 = load i64, i64* %7
%20 = add nsw i64 %18, %19
store i64 %20, i64* %9
%21 = bitcast [31 x i32]* %10 to i8*
store i32 0, i32* %11
%22 = load i64, i64* %9
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32, i32* %11
%26 = add nsw i32 %25, 1
store i32 %26, i32* %11
br label %47
27: ; preds = %17
br label %28
28: ; preds = %31, %27
%29 = load i64, i64* %9
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %46
31: ; preds = %28
%32 = load i64, i64* %9
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = srem i64 %32, %34
%36 = trunc i64 %35 to i32
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [31 x i32], [31 x i32]* %10, i64 0, i64 %38
store i32 %36, i32* %39
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = load i64, i64* %9
%43 = sdiv i64 %42, %41
store i64 %43, i64* %9
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
br label %28
46: ; preds = %28
br label %47
47: ; preds = %46, %24
%48 = load i32, i32* %11
%49 = sub nsw i32 %48, 1
store i32 %49, i32* %12
br label %50
50: ; preds = %59, %47
%51 = load i32, i32* %12
%52 = icmp sge i32 %51, 0
br i1 %52, label %53, label %62
53: ; preds = %50
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [31 x i32], [31 x i32]* %10, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %53
%60 = load i32, i32* %12
%61 = add nsw i32 %60, -1
store i32 %61, i32* %12
br label %50
62: ; preds = %50
%63 = load i32, i32* @EXIT_SUCCESS
store i32 %63, i32* %3
br label %64
64: ; preds = %62, %15
%65 = load i32, i32* %3
ret i32 %65
}

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