char *strerror(int errnum) {
  static char message[32] = "error ";
  char numbuf[32];
  char *p;
  p = numbuf + sizeof numbuf;
  *--p = '\0';
  do {
    *--p = (errnum % 10) + '0';
    errnum /= 10;
  } while (errnum);
  return (char *)memcpy(message + 6, p, (numbuf + sizeof numbuf) - p);
}


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,-0x1(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    113a <strerror+0x2a>
mov    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
add    $0x20,%rdx
mov    -0x38(%rbp),%rax
sub    %rax,%rdx
lea    0x2ea2(%rip),%rdi
add    $0x6,%rdi
call   1030 <memcpy@plt>
lea    0x2e92(%rip),%rax
add    $0x6,%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
push   %rbx
sub    $0x20,%rsp
movb   $0x0,0x1f(%rsp)
mov    $0xffffffffffffffff,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %edi,%rax
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rdi
add    %ecx,%edi
lea    (%rdi,%rdi,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%esi
sub    %ecx,%esi
add    $0x30,%sil
mov    %sil,0x1f(%rsp,%rdx,1)
add    $0x9,%eax
add    $0xffffffffffffffff,%rdx
cmp    $0x12,%eax
ja     1130 <strerror+0x20>
lea    (%rsp,%rdx,1),%rsi
add    $0x20,%rsi
neg    %rdx
lea    0x2ebe(%rip),%rbx
mov    %rbx,%rdi
call   1030 <memcpy@plt>
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@strerror.message = internal global [32 x i8] c"error \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i8* @strerror(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca i8*
store i32 %0, i32* %2
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds i8, i8* %5, i64 32
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i32 -1
store i8* %8, i8** %4
store i8 0, i8* %8
br label %9
9: ; preds = %18, %1
%10 = load i32, i32* %2
%11 = srem i32 %10, 10
%12 = add nsw i32 %11, 48
%13 = trunc i32 %12 to i8
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 -1
store i8* %15, i8** %4
store i8 %13, i8* %15
%16 = load i32, i32* %2
%17 = sdiv i32 %16, 10
store i32 %17, i32* %2
br label %18
18: ; preds = %9
%19 = load i32, i32* %2
%20 = icmp ne i32 %19, 0
br i1 %20, label %9, label %21
21: ; preds = %18
%22 = load i8*, i8** %4
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 32
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @strerror.message, i64 0, i64 6)
}

LLVM IR (-O2):
@strerror.message = internal global [32 x i8] c"error \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i8* @strerror(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 31
store i8 0, i8* %4
br label %5
5: ; preds = %5, %1
%6 = phi i32 [ %0, %1 ], [ %12, %5 ]
%7 = phi i8* [ %4, %1 ], [ %11, %5 ]
%8 = srem i32 %6, 10
%9 = trunc i32 %8 to i8
%10 = add nsw i8 %9, 48
%11 = getelementptr inbounds i8, i8* %7, i64 -1
store i8 %10, i8* %11
%12 = sdiv i32 %6, 10
%13 = add i32 %6, 9
%14 = icmp ult i32 %13, 19
br i1 %14, label %15, label %5
15: ; preds = %5
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 32
%17 = ptrtoint i8* %16 to i64
%18 = ptrtoint i8* %11 to i64
%19 = sub i64 %17, %18
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @strerror.message, i64 0, i64 6)
}