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


x86 assembly (clang, -O0):
<check_errno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x80,%eax
je     1217 <check_errno+0xf7>
jmp    1177 <check_errno+0x57>
mov    -0x8(%rbp),%eax
sub    $0x81,%eax
je     11da <check_errno+0xba>
jmp    118a <check_errno+0x6a>
mov    -0x8(%rbp),%eax
sub    $0x82,%eax
jne    1254 <check_errno+0x134>
jmp    119d <check_errno+0x7d>
jmp    11a2 <check_errno+0x82>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1291 <check_errno+0x171>
jmp    11df <check_errno+0xbf>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1291 <check_errno+0x171>
jmp    121c <check_errno+0xfc>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1291 <check_errno+0x171>
jmp    1259 <check_errno+0x139>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1291 <check_errno+0x171>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_errno>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <pthread_self@plt>
lea    0xebf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0xffffff80,%ebx
cmp    $0x2,%ebx
ja     117f <check_errno+0x4f>
movslq %ebx,%rax
lea    0xec2(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    1186 <check_errno+0x56>
lea    0xea2(%rip),%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
lea    0xe6c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

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

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