char *strerror(int errnum) {
  static char message[32] = "error ";
  char numbuf[32];
  char *p;
  unsigned int e = (unsigned int)errnum;
  extern const int sys_nerr;
  extern const char *const sys_errlist[];
  if (e < (unsigned int)sys_nerr && sys_errlist[e])
    return (char *)sys_errlist[e];
  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,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2ebd(%rip),%rcx
cmp    (%rcx),%eax
jae    1163 <strerror+0x53>
mov    -0x3c(%rbp),%eax
mov    %eax,%ecx
mov    0x2eb9(%rip),%rax
cmpq   $0x0,(%rax,%rcx,8)
je     1163 <strerror+0x53>
mov    -0x3c(%rbp),%eax
mov    %eax,%ecx
mov    0x2ea2(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <strerror+0xdc>
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    1182 <strerror+0x72>
mov    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
add    $0x20,%rdx
mov    -0x38(%rbp),%rax
sub    %rax,%rdx
lea    0x2e58(%rip),%rdi
add    $0x6,%rdi
call   1030 <memcpy@plt>
lea    0x2e48(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
sub    $0x28,%rsp
mov    0x2ecd(%rip),%rax
cmp    %edi,(%rax)
jbe    1136 <strerror+0x26>
mov    %edi,%eax
mov    0x2ed0(%rip),%rcx
mov    (%rcx,%rax,8),%rax
test   %rax,%rax
je     1136 <strerror+0x26>
add    $0x28,%rsp
ret
movb   $0x0,0x1f(%rsp)
mov    $0xffffffffffffffff,%rdx
mov    $0xcccccccd,%r8d
nopl   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     1150 <strerror+0x40>
lea    (%rsp,%rdx,1),%rsi
add    $0x20,%rsi
neg    %rdx
lea    0x2eaf(%rip),%rdi
call   1030 <memcpy@plt>
lea    0x2e9d(%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"
@sys_nerr = external constant i32
@sys_errlist = external constant [0 x i8*]
define i8* @strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = load i32, i32* @sys_nerr
%10 = icmp ult i32 %8, %9
br i1 %10, label %11, label %22
11: ; preds = %1
%12 = load i32, i32* %6
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [0 x i8*], [0 x i8*]* @sys_errlist, i64 0, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i32, i32* %6
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [0 x i8*], [0 x i8*]* @sys_errlist, i64 0, i64 %19
%21 = load i8*, i8** %20
store i8* %21, i8** %2
br label %47
22: ; preds = %11, %1
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 32
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 -1
store i8* %26, i8** %5
store i8 0, i8* %26
br label %27
27: ; preds = %36, %22
%28 = load i32, i32* %6
%29 = urem i32 %28, 10
%30 = add i32 %29, 48
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 -1
store i8* %33, i8** %5
store i8 %31, i8* %33
%34 = load i32, i32* %6
%35 = udiv i32 %34, 10
store i32 %35, i32* %6
br label %36
36: ; preds = %27
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 0
br i1 %38, label %27, label %39
39: ; preds = %36
%40 = load i8*, i8** %5
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%42 = getelementptr inbounds i8, i8* %41, i64 32
%43 = load i8*, i8** %5
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @strerror.message, i64 0, i64 0), i8** %2
br label %47
47: ; preds = %39, %17
%48 = load i8*, i8** %2
ret i8* %48
}

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"
@sys_nerr = external constant i32
@sys_errlist = external constant [0 x i8*]
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 = load i32, i32* @sys_nerr
%5 = icmp ugt i32 %4, %0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = zext i32 %0 to i64
%8 = getelementptr inbounds [0 x i8*], [0 x i8*]* @sys_errlist, i64 0, i64 %7
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %27
11: ; preds = %6, %1
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 31
store i8 0, i8* %12
br label %13
13: ; preds = %13, %11
%14 = phi i8* [ %12, %11 ], [ %19, %13 ]
%15 = phi i32 [ %0, %11 ], [ %20, %13 ]
%16 = urem i32 %15, 10
%17 = trunc i32 %16 to i8
%18 = or i8 %17, 48
%19 = getelementptr inbounds i8, i8* %14, i64 -1
store i8 %18, i8* %19
%20 = udiv i32 %15, 10
%21 = icmp ult i32 %15, 10
br i1 %21, label %22, label %13
22: ; preds = %13
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 32
%24 = ptrtoint i8* %23 to i64
%25 = ptrtoint i8* %19 to i64
%26 = sub i64 %24, %25
br label %27
27: ; preds = %6, %22
%28 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @strerror.message, i64 0, i64 0), %22 ], [ %9, %6 ]
ret i8* %28
}