char *strerror(int err) {
  static struct errlist {
    int err;
    char *what;
  } errlist[] = {
      {0, "No error"},
      {1, "Function number invalid"},
      {2, "File not found"},
      {3, "Path not found"},
      {4, "Too many open files"},
      {5, "Access denied"},
      {6, "Invalid handle"},
      {12, "Access code invalid"},
      {39, "Insufficient disk space"},
  };
  struct errlist *ep;
  static char unknown[] = "Error 65535";
  unsigned e;
  char *p;
  for (ep = errlist; ep < errlist + sizeof(errlist) / sizeof(errlist[0]);
       ep++) {
    if (ep->err == err)
      return ep->what;
  }
  p = unknown + sizeof(unknown) - 1;
  e = err;
  do
    *--p = '0' + (e % 10);
  while ((e /= 10) > 0);
  strcpy(unknown + 6, p);
  return unknown;
}


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
lea    0x2f0e(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0x2f03(%rip),%rax
add    $0x90,%rax
cmp    %rax,-0x18(%rbp)
jae    1173 <strerror+0x63>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0xc(%rbp),%eax
jne    115d <strerror+0x4d>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11de <strerror+0xce>
jmp    1162 <strerror+0x52>
mov    -0x18(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
jmp    1126 <strerror+0x16>
lea    0x2f46(%rip),%rax
add    $0xb,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
ja     1188 <strerror+0x78>
mov    -0x28(%rbp),%rsi
lea    0x2ef8(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ee6(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
push   %rax
lea    0x2c78(%rip),%rax
lea    0x2d01(%rip),%rcx
nop
cmp    %edi,(%rax)
je     1179 <strerror+0x69>
add    $0x10,%rax
cmp    %rcx,%rax
jb     1120 <strerror+0x10>
lea    0x2eff(%rip),%rsi
mov    $0xcccccccd,%r8d
nopw   0x0(%rax,%rax,1)
mov    %edi,%ecx
imul   %r8,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %edi,%eax
sub    %edx,%eax
or     $0x30,%al
mov    %al,-0x1(%rsi)
add    $0xffffffffffffffff,%rsi
cmp    $0x9,%edi
mov    %ecx,%edi
ja     1140 <strerror+0x30>
lea    0x2ec3(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2eb1(%rip),%rax
pop    %rcx
ret
mov    0x8(%rax),%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.errlist = type { i32, i8* }
@strerror.errlist = internal global [9 x %struct.errlist] [%struct.errlist { i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0) }, %struct.errlist { i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i32 0, i32 0) }, %struct.errlist { i32 2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i32 0, i32 0) }, %struct.errlist { i32 3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i32 0, i32 0) }, %struct.errlist { i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i32 0, i32 0) }, %struct.errlist { i32 5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i32 0, i32 0) }, %struct.errlist { i32 6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i32 0, i32 0) }, %struct.errlist { i32 12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i32 0, i32 0) }, %struct.errlist { i32 39, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i32 0, i32 0) }]
@.str = [9 x i8] c"No error\00"
@.str.1 = [24 x i8] c"Function number invalid\00"
@.str.2 = [15 x i8] c"File not found\00"
@.str.3 = [15 x i8] c"Path not found\00"
@.str.4 = [20 x i8] c"Too many open files\00"
@.str.5 = [14 x i8] c"Access denied\00"
@.str.6 = [15 x i8] c"Invalid handle\00"
@.str.7 = [20 x i8] c"Access code invalid\00"
@.str.8 = [24 x i8] c"Insufficient disk space\00"
@strerror.unknown = internal global [12 x i8] c"Error 65535\00"
define i8* @strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.errlist*
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store %struct.errlist* getelementptr inbounds ([9 x %struct.errlist], [9 x %struct.errlist]* @strerror.errlist, i64 0, i64 0), %struct.errlist** %4
br label %7
7: ; preds = %21, %1
%8 = load %struct.errlist*, %struct.errlist** %4
%9 = icmp ult %struct.errlist* %8, getelementptr inbounds ([9 x %struct.errlist], [9 x %struct.errlist]* @strerror.errlist, i64 1, i64 0)
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load %struct.errlist*, %struct.errlist** %4
%12 = getelementptr inbounds %struct.errlist, %struct.errlist* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* %3
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load %struct.errlist*, %struct.errlist** %4
%18 = getelementptr inbounds %struct.errlist, %struct.errlist* %17, i32 0, i32 1
%19 = load i8*, i8** %18
store i8* %19, i8** %2
br label %40
20: ; preds = %10
br label %21
21: ; preds = %20
%22 = load %struct.errlist*, %struct.errlist** %4
%23 = getelementptr inbounds %struct.errlist, %struct.errlist* %22, i32 1
store %struct.errlist* %23, %struct.errlist** %4
br label %7
24: ; preds = %7
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @strerror.unknown, i64 1, i64 -1), i8** %6
%25 = load i32, i32* %3
store i32 %25, i32* %5
br label %26
26: ; preds = %33, %24
%27 = load i32, i32* %5
%28 = urem i32 %27, 10
%29 = add i32 48, %28
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %6
store i8 %30, i8* %32
br label %33
33: ; preds = %26
%34 = load i32, i32* %5
%35 = udiv i32 %34, 10
store i32 %35, i32* %5
%36 = icmp ugt i32 %35, 0
br i1 %36, label %26, label %37
37: ; preds = %33
%38 = load i8*, i8** %6
%39 = call i8* @strcpy(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @strerror.unknown, i64 0, i64 6), i8* %38)
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @strerror.unknown, i64 0, i64 0), i8** %2
br label %40
40: ; preds = %37, %16
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
%struct.errlist = type { i32, i8* }
@strerror.errlist = internal constant [9 x %struct.errlist] [%struct.errlist { i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0) }, %struct.errlist { i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i32 0, i32 0) }, %struct.errlist { i32 2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i32 0, i32 0) }, %struct.errlist { i32 3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i32 0, i32 0) }, %struct.errlist { i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i32 0, i32 0) }, %struct.errlist { i32 5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i32 0, i32 0) }, %struct.errlist { i32 6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i32 0, i32 0) }, %struct.errlist { i32 12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i32 0, i32 0) }, %struct.errlist { i32 39, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i32 0, i32 0) }]
@.str = [9 x i8] c"No error\00"
@.str.1 = [24 x i8] c"Function number invalid\00"
@.str.2 = [15 x i8] c"File not found\00"
@.str.3 = [15 x i8] c"Path not found\00"
@.str.4 = [20 x i8] c"Too many open files\00"
@.str.5 = [14 x i8] c"Access denied\00"
@.str.6 = [15 x i8] c"Invalid handle\00"
@.str.7 = [20 x i8] c"Access code invalid\00"
@.str.8 = [24 x i8] c"Insufficient disk space\00"
@strerror.unknown = internal global [12 x i8] c"Error 65535\00"
define i8* @strerror(i32 %0) {
br label %2
2: ; preds = %1, %10
%3 = phi %struct.errlist* [ getelementptr inbounds ([9 x %struct.errlist], [9 x %struct.errlist]* @strerror.errlist, i64 0, i64 0), %1 ], [ %11, %10 ]
%4 = getelementptr inbounds %struct.errlist, %struct.errlist* %3, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = getelementptr inbounds %struct.errlist, %struct.errlist* %3, i64 0, i32 1
%9 = load i8*, i8** %8
br label %24
10: ; preds = %2
%11 = getelementptr inbounds %struct.errlist, %struct.errlist* %3, i64 1
%12 = icmp ult %struct.errlist* %11, getelementptr inbounds ([9 x %struct.errlist], [9 x %struct.errlist]* @strerror.errlist, i64 1, i64 0)
br i1 %12, label %2, label %13
13: ; preds = %10, %13
%14 = phi i32 [ %20, %13 ], [ %0, %10 ]
%15 = phi i8* [ %19, %13 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @strerror.unknown, i64 0, i64 11), %10 ]
%16 = urem i32 %14, 10
%17 = trunc i32 %16 to i8
%18 = or i8 %17, 48
%19 = getelementptr inbounds i8, i8* %15, i64 -1
store i8 %18, i8* %19
%20 = udiv i32 %14, 10
%21 = icmp ult i32 %14, 10
br i1 %21, label %22, label %13
22: ; preds = %13
%23 = tail call i8* @strcpy(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @strerror.unknown, i64 0, i64 6), i8* %19)
br label %24
24: ; preds = %22, %7
%25 = phi i8* [ %9, %7 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @strerror.unknown, i64 0, i64 0), %22 ]
ret i8* %25
}