#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 ctoi(char);
char itoc(int);
void add_digits(char a, char b, char c, char *total, char *carry) {
  int sum = ctoi(a) + ctoi(b) + ctoi(c);
  *total = itoc(sum % 10);
  *carry = itoc(sum / 10);
}


x86 assembly (clang, -O0):
<add_digits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %dl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
mov    %rcx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <ctoi@plt>
mov    %eax,-0x24(%rbp)
movsbl -0x2(%rbp),%edi
call   1030 <ctoi@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
movsbl -0x3(%rbp),%edi
call   1030 <ctoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1040 <itoc@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <itoc@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_digits>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,%ebx
call   1030 <ctoi@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <ctoi@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r12d,%edi
call   1030 <ctoi@plt>
add    %ebx,%eax
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
call   1040 <itoc@plt>
mov    %al,(%r15)
mov    %ebx,%edi
call   1040 <itoc@plt>
mov    %al,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @add_digits(i8 signext %0, i8 signext %1, i8 signext %2, i8* %3, i8* %4) {
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8 %0, i8* %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%12 = load i8, i8* %6
%13 = call i32 @ctoi(i8 signext %12)
%14 = load i8, i8* %7
%15 = call i32 @ctoi(i8 signext %14)
%16 = add nsw i32 %13, %15
%17 = load i8, i8* %8
%18 = call i32 @ctoi(i8 signext %17)
%19 = add nsw i32 %16, %18
store i32 %19, i32* %11
%20 = load i32, i32* %11
%21 = srem i32 %20, 10
%22 = call signext i8 @itoc(i32 %21)
%23 = load i8*, i8** %9
store i8 %22, i8* %23
%24 = load i32, i32* %11
%25 = sdiv i32 %24, 10
%26 = call signext i8 @itoc(i32 %25)
%27 = load i8*, i8** %10
store i8 %26, i8* %27
ret void
}

LLVM IR (-O2):
define void @add_digits(i8 signext %0, i8 signext %1, i8 signext %2, i8* nocapture writeonly %3, i8* nocapture writeonly %4) {
%6 = tail call i32 @ctoi(i8 signext %0)
%7 = tail call i32 @ctoi(i8 signext %1)
%8 = add nsw i32 %7, %6
%9 = tail call i32 @ctoi(i8 signext %2)
%10 = add nsw i32 %8, %9
%11 = srem i32 %10, 10
%12 = tail call signext i8 @itoc(i32 %11)
store i8 %12, i8* %3
%13 = sdiv i32 %10, 10
%14 = tail call signext i8 @itoc(i32 %13)
store i8 %14, i8* %4
ret void
}