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


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%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    -0x3c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %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    -0x3c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    1140 <strerror+0x30>
mov    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
add    $0x20,%rdx
mov    -0x38(%rbp),%rax
sub    %rax,%rdx
lea    0x2e9a(%rip),%rdi
add    $0x6,%rdi
call   1030 <memcpy@plt>
lea    0x2e8a(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
sub    $0x28,%rsp
movb   $0x0,0x1f(%rsp)
mov    $0xffffffffffffffff,%rdx
mov    $0xcccccccd,%r8d
cs nopw 0x0(%rax,%rax,1)
mov    %edi,%ecx
imul   %r8,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %edi,%eax
sub    %esi,%eax
or     $0x30,%al
mov    %al,0x1f(%rsp,%rdx,1)
add    $0xffffffffffffffff,%rdx
cmp    $0x9,%edi
mov    %ecx,%edi
ja     1130 <strerror+0x20>
lea    (%rsp,%rdx,1),%rsi
add    $0x20,%rsi
neg    %rdx
lea    0x2ecf(%rip),%rdi
call   1030 <memcpy@plt>
lea    0x2ebd(%rip),%rax
add    $0x28,%rsp
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*
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
store i32 %6, i32* %5
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds i8, i8* %7, i64 32
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i32 -1
store i8* %10, i8** %4
store i8 0, i8* %10
br label %11
11: ; preds = %20, %1
%12 = load i32, i32* %5
%13 = urem i32 %12, 10
%14 = add i32 %13, 48
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 -1
store i8* %17, i8** %4
store i8 %15, i8* %17
%18 = load i32, i32* %5
%19 = udiv i32 %18, 10
store i32 %19, i32* %5
br label %20
20: ; preds = %11
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %11, label %23
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%26 = getelementptr inbounds i8, i8* %25, i64 32
%27 = load i8*, i8** %4
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @strerror.message, i64 0, i64 0)
}

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 i8* [ %4, %1 ], [ %11, %5 ]
%7 = phi i32 [ %0, %1 ], [ %12, %5 ]
%8 = urem i32 %7, 10
%9 = trunc i32 %8 to i8
%10 = or i8 %9, 48
%11 = getelementptr inbounds i8, i8* %6, i64 -1
store i8 %10, i8* %11
%12 = udiv i32 %7, 10
%13 = icmp ult i32 %7, 10
br i1 %13, label %14, label %5
14: ; preds = %5
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 32
%16 = ptrtoint i8* %15 to i64
%17 = ptrtoint i8* %11 to i64
%18 = sub i64 %16, %17
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @strerror.message, i64 0, i64 0)
}