#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
#define EACCES 129
#define EBADF 128
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strerror(int errnum) {
  static char buf[1024];
  switch (errnum) {
  case EBADF:
    return "Bad file.\n";
  case EACCES:
    return "Access prohibited.\n";
  }
  sprintf(buf, "Unkown error: %d", errnum);
  return buf;
}


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x80,%eax
je     1144 <strerror+0x34>
jmp    1131 <strerror+0x21>
mov    -0x10(%rbp),%eax
sub    $0x81,%eax
je     1154 <strerror+0x44>
jmp    1164 <strerror+0x54>
lea    0xeb5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1185 <strerror+0x75>
lea    0xeb0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1185 <strerror+0x75>
mov    -0xc(%rbp),%edx
lea    0x2ed2(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2ebf(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
push   %rbx
cmp    $0x80,%edi
je     112c <strerror+0x1c>
mov    %edi,%edx
cmp    $0x81,%edi
jne    1135 <strerror+0x25>
lea    0xee1(%rip),%rbx
jmp    114b <strerror+0x3b>
lea    0xecd(%rip),%rbx
jmp    114b <strerror+0x3b>
lea    0x2f04(%rip),%rbx
lea    0xedc(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@strerror.buf = internal global [1024 x i8] zeroinitializer
@.str = [11 x i8] c"Bad file.\0A\00"
@.str.1 = [20 x i8] c"Access prohibited.\0A\00"
@.str.2 = [17 x i8] c"Unkown error: %d\00"
define i8* @strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %7 [
i32 128, label %5
i32 129, label %6
]
5: ; preds = %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %2
br label %10
6: ; preds = %1
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %10
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i32 @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @strerror.buf, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %8)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @strerror.buf, i64 0, i64 0), i8** %2
br label %10
10: ; preds = %7, %6, %5
%11 = load i8*, i8** %2
ret i8* %11
}

LLVM IR (-O2):
@strerror.buf = internal global [1024 x i8] zeroinitializer
@.str = [11 x i8] c"Bad file.\0A\00"
@.str.1 = [20 x i8] c"Access prohibited.\0A\00"
@.str.2 = [17 x i8] c"Unkown error: %d\00"
define i8* @strerror(i32 %0) {
switch i32 %0, label %3 [
i32 128, label %5
i32 129, label %2
]
2: ; preds = %1
br label %5
3: ; preds = %1
%4 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @strerror.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %5
5: ; preds = %1, %3, %2
%6 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @strerror.buf, i64 0, i64 0), %3 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %6
}