#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 EAGAIN 131
#define EDEADLK 130
#define EINVAL 129
#define ETIMEDOUT 128
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ pthread_self();
void show_errno(int err) {
  switch (err) {
  case EINVAL:
    do {
      printf("%d--", 35);
      printf("[%u]-- %s", (unsigned int)pthread_self(), "EINVAL");
      printf("\n");
    } while (0);
    break;
  case ETIMEDOUT:
    do {
      printf("%d--", 38);
      printf("[%u]-- %s", (unsigned int)pthread_self(), "ETIMEDOUT");
      printf("\n");
    } while (0);
    break;
  case EAGAIN:
    do {
      printf("%d--", 41);
      printf("[%u]-- %s", (unsigned int)pthread_self(), "EAGAIN");
      printf("\n");
    } while (0);
    break;
  case EDEADLK:
    do {
      printf("%d--", 44);
      printf("[%u]-- %s", (unsigned int)pthread_self(), "EDEADLK");
      printf("\n");
    } while (0);
    break;
  default:
    do {
      printf("%d--", 47);
      printf("[%u]-- %s", (unsigned int)pthread_self(), "no such errno");
      printf("\n");
    } while (0);
  }
}


x86 assembly (clang, -O0):
<show_errno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     1278 <show_errno+0x158>
mov    -0x10(%rbp),%rax
lea    0xeb5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    1159 <show_errno+0x39>
lea    0xeb0(%rip),%rdi
mov    $0x23,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xe99(%rip),%rdi
lea    0xe9c(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c1 <show_errno+0x1a1>
jmp    11a2 <show_errno+0x82>
lea    0xe67(%rip),%rdi
mov    $0x26,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xe50(%rip),%rdi
lea    0xe5c(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c1 <show_errno+0x1a1>
jmp    11eb <show_errno+0xcb>
lea    0xe1e(%rip),%rdi
mov    $0x29,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xe07(%rip),%rdi
lea    0xe1d(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c1 <show_errno+0x1a1>
jmp    1234 <show_errno+0x114>
lea    0xdd5(%rip),%rdi
mov    $0x2c,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xdbe(%rip),%rdi
lea    0xddb(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c1 <show_errno+0x1a1>
jmp    127d <show_errno+0x15d>
lea    0xd8c(%rip),%rdi
mov    $0x2f,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xd75(%rip),%rdi
lea    0xd9a(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c1 <show_errno+0x1a1>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_errno>:
push   %rbx
add    $0xffffff80,%edi
cmp    $0x3,%edi
ja     1156 <show_errno+0x26>
movslq %edi,%rax
lea    0xefd(%rip),%rcx
mov    (%rcx,%rax,4),%esi
lea    0xf03(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    1162 <show_errno+0x32>
lea    0xed2(%rip),%rbx
mov    $0x2f,%esi
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <pthread_self@plt>
lea    0xe87(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%d--\00"
@.str.1 = [10 x i8] c"[%u]-- %s\00"
@.str.2 = [7 x i8] c"EINVAL\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [10 x i8] c"ETIMEDOUT\00"
@.str.5 = [7 x i8] c"EAGAIN\00"
@.str.6 = [8 x i8] c"EDEADLK\00"
@.str.7 = [14 x i8] c"no such errno\00"
define void @show_errno(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %36 [
i32 129, label %4
i32 128, label %12
i32 131, label %20
i32 130, label %28
]
4: ; preds = %1
br label %5
5: ; preds = %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 35)
%7 = call i64 (...) @pthread_self()
%8 = trunc i64 %7 to i32
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %11
11: ; preds = %5
br label %44
12: ; preds = %1
br label %13
13: ; preds = %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 38)
%15 = call i64 (...) @pthread_self()
%16 = trunc i64 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %13
br label %44
20: ; preds = %1
br label %21
21: ; preds = %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 41)
%23 = call i64 (...) @pthread_self()
%24 = trunc i64 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %21
br label %44
28: ; preds = %1
br label %29
29: ; preds = %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 44)
%31 = call i64 (...) @pthread_self()
%32 = trunc i64 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %29
br label %44
36: ; preds = %1
br label %37
37: ; preds = %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 47)
%39 = call i64 (...) @pthread_self()
%40 = trunc i64 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %40, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %37
br label %44
44: ; preds = %43, %35, %27, %19, %11
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d--\00"
@.str.1 = [10 x i8] c"[%u]-- %s\00"
@.str.2 = [7 x i8] c"EINVAL\00"
@.str.4 = [10 x i8] c"ETIMEDOUT\00"
@.str.5 = [7 x i8] c"EAGAIN\00"
@.str.6 = [8 x i8] c"EDEADLK\00"
@.str.7 = [14 x i8] c"no such errno\00"
@switch.table.show_errno = [4 x i32] [i32 38, i32 35, i32 44, i32 41]
@reltable.show_errno = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.show_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.show_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.6 to i64), i64 ptrtoint ([4 x i32]* @reltable.show_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.5 to i64), i64 ptrtoint ([4 x i32]* @reltable.show_errno to i64)) to i32)]
define void @show_errno(i32 %0) {
%2 = add i32 %0, -128
%3 = icmp ult i32 %2, 4
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.show_errno, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = sext i32 %2 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.show_errno to i8*), i64 %9)
br label %11
11: ; preds = %1, %4
%12 = phi i32 [ %7, %4 ], [ 47, %1 ]
%13 = phi i8* [ %10, %4 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), %1 ]
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12)
%15 = tail call i64 (...) @pthread_self()
%16 = trunc i64 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %13)
%18 = tail call i32 @putchar(i32 10)
ret void
}