#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 *, int *, int *, int *);
int main() {
  int num1, num2, k, tmp1, tmp2, flag;
  while (scanf("%d%d%d", &num1, &num2, &k) != EOF) {
    if (num1 == 0 && num2 == 0)
      return 0;
    tmp1 = num1;
    tmp2 = num2;
    flag = 1;
    while (k) {
      if (tmp1 % 10 == tmp2 % 10) {
        k--;
        tmp1 /= 10;
        tmp2 /= 10;
      } else {
        flag = 0;
        break;
      }
    }
    if (flag)
      printf("-1\n");
    else
      printf("%d\n", num1 + num2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1040 <scanf@plt>
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%rax
je     122b <main+0x10b>
cmpl   $0x0,-0x8(%rbp)
jne    1177 <main+0x57>
cmpl   $0x0,-0xc(%rbp)
jne    1177 <main+0x57>
movl   $0x0,-0x4(%rbp)
jmp    1232 <main+0x112>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11f5 <main+0xd5>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x20(%rbp),%edx
cmp    %eax,%edx
jne    11e4 <main+0xc4>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
jmp    11f0 <main+0xd0>
movl   $0x0,-0x1c(%rbp)
jmp    11f5 <main+0xd5>
jmp    118a <main+0x6a>
cmpl   $0x0,-0x1c(%rbp)
je     1212 <main+0xf2>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1226 <main+0x106>
mov    -0x8(%rbp),%esi
add    -0xc(%rbp),%esi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    112f <main+0xf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xebb(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1050 <scanf@plt>
mov    0x2e88(%rip),%r15
cmp    (%r15),%rax
jne    1176 <main+0x46>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%r14
jmp    11b6 <main+0x86>
nopw   0x0(%rax,%rax,1)
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5d(%rip),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1050 <scanf@plt>
cmp    (%r15),%rax
je     1165 <main+0x35>
mov    0x14(%rsp),%r8d
mov    0x10(%rsp),%esi
mov    %r8d,%ecx
or     %esi,%ecx
je     1165 <main+0x35>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
je     1190 <main+0x60>
add    $0xffffffff,%ecx
mov    %esi,%edx
mov    %r8d,%edi
cs nopw 0x0(%rax,%rax,1)
movslq %edi,%rbx
imul   $0x66666667,%rbx,%rdi
mov    %rdi,%rbp
shr    $0x3f,%rbp
sar    $0x22,%rdi
add    %ebp,%edi
lea    (%rdi,%rdi,1),%ebp
lea    0x0(%rbp,%rbp,4),%ebp
sub    %ebp,%ebx
movslq %edx,%rbp
imul   $0x66666667,%rbp,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x22,%rdx
add    %eax,%edx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
cmp    %ebp,%ebx
jne    1240 <main+0x110>
mov    %ecx,0xc(%rsp)
add    $0xffffffff,%ecx
jb     11e0 <main+0xb0>
jmp    1190 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %r8d,%esi
lea    0xdbd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119c <main+0x6c>

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

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