writeint_(x, a, len) int *x;
char *a;
int *len;
{
  char b[20];
  int i;
  sprintf(b, "%d", *x);
  *len = strlen(b);
  for (i = 0; i < *len; i++)
    a[i] = b[i];
}


x86 assembly (clang, -O0):
<writeint_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xebb(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    1194 <writeint_+0x74>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1164 <writeint_+0x44>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeint_>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    (%rdi),%edx
lea    0xec8(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,(%rbx)
test   %eax,%eax
jle    1174 <writeint_+0x54>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rsp,%rax,1),%ecx
mov    %cl,(%r14,%rax,1)
add    $0x1,%rax
movslq (%rbx),%rcx
cmp    %rcx,%rax
jl     1160 <writeint_+0x40>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @writeint_(i32* nocapture %0, i8* nocapture writeonly %1, i32* nocapture %2) {
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* %0
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i64 @strlen(i8* %5)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %3, %11
%12 = phi i64 [ %16, %11 ], [ 0, %3 ]
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 %14, i8* %15
%16 = add nuw nsw i64 %12, 1
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %11, label %20
20: ; preds = %11, %3
ret i32 undef
}