#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 */
typedef int td_err_e;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
#define TD_BADKEY 148
#define TD_BADPH 147
#define TD_BADSH 146
#define TD_BADTA 145
#define TD_BADTH 144
#define TD_DBERR 143
#define TD_ERR 142
#define TD_MALLOC 141
#define TD_NOAPLIC 140
#define TD_NOCAPAB 139
#define TD_NOEVENT 138
#define TD_NOFPREGS 137
#define TD_NOLIBTHREAD 136
#define TD_NOLWP 135
#define TD_NOMSG 134
#define TD_NOSV 133
#define TD_NOTHR 132
#define TD_NOTSD 131
#define TD_NOXREGS 130
#define TD_OK 129
#define TD_PARTIALREG 128
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *thread_db_err_str(td_err_e err) {
  static char buf[64];
  switch (err) {
  case TD_OK:
    return "generic 'call succeeded'";
  case TD_ERR:
    return "generic error";
  case TD_NOTHR:
    return "no thread to satisfy query";
  case TD_NOSV:
    return "no sync handle to satisfy query";
  case TD_NOLWP:
    return "no LWP to satisfy query";
  case TD_BADPH:
    return "invalid process handle";
  case TD_BADTH:
    return "invalid thread handle";
  case TD_BADSH:
    return "invalid synchronization handle";
  case TD_BADTA:
    return "invalid thread agent";
  case TD_BADKEY:
    return "invalid key";
  case TD_NOMSG:
    return "no event message for getmsg";
  case TD_NOFPREGS:
    return "FPU register set not available";
  case TD_NOLIBTHREAD:
    return "application not linked with libthread";
  case TD_NOEVENT:
    return "requested event is not supported";
  case TD_NOCAPAB:
    return "capability not available";
  case TD_DBERR:
    return "debugger service failed";
  case TD_NOAPLIC:
    return "operation not applicable to";
  case TD_NOTSD:
    return "no thread-specific data for this thread";
  case TD_MALLOC:
    return "malloc failed";
  case TD_PARTIALREG:
    return "only part of register set was written/read";
  case TD_NOXREGS:
    return "X register set not available for this thread";
  default:
    snprintf(buf, sizeof(buf), "unknown thread_db error '%d'", err);
    return buf;
  }
}


x86 assembly (clang, -O0):
<thread_db_err_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x14,%eax
ja     1294 <thread_db_err_str+0x184>
mov    -0x18(%rbp),%rax
lea    0xec5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf09(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf12(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf10(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf1b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf2b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf33(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf3a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf40(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf4f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf54(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf50(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf5c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf6b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf81(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf92(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xf9b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xfa3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xfaf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xfc7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xfc5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
lea    0xfe0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <thread_db_err_str+0x1aa>
mov    -0xc(%rbp),%ecx
lea    0x2da2(%rip),%rdi
mov    $0x40,%esi
lea    0xfee(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2d8a(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_db_err_str>:
push   %rbx
mov    %edi,%ecx
lea    -0x80(%rcx),%eax
cmp    $0x15,%eax
jae    112d <thread_db_err_str+0x1d>
cltq
lea    0x1140(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    1148 <thread_db_err_str+0x38>
lea    0x2f0c(%rip),%rbx
lea    0x1109(%rip),%rdx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@thread_db_err_str.buf = internal global [64 x i8] zeroinitializer
@.str = [25 x i8] c"generic 'call succeeded'\00"
@.str.1 = [14 x i8] c"generic error\00"
@.str.2 = [27 x i8] c"no thread to satisfy query\00"
@.str.3 = [32 x i8] c"no sync handle to satisfy query\00"
@.str.4 = [24 x i8] c"no LWP to satisfy query\00"
@.str.5 = [23 x i8] c"invalid process handle\00"
@.str.6 = [22 x i8] c"invalid thread handle\00"
@.str.7 = [31 x i8] c"invalid synchronization handle\00"
@.str.8 = [21 x i8] c"invalid thread agent\00"
@.str.9 = [12 x i8] c"invalid key\00"
@.str.10 = [28 x i8] c"no event message for getmsg\00"
@.str.11 = [31 x i8] c"FPU register set not available\00"
@.str.12 = [38 x i8] c"application not linked with libthread\00"
@.str.13 = [33 x i8] c"requested event is not supported\00"
@.str.14 = [25 x i8] c"capability not available\00"
@.str.15 = [24 x i8] c"debugger service failed\00"
@.str.16 = [28 x i8] c"operation not applicable to\00"
@.str.17 = [40 x i8] c"no thread-specific data for this thread\00"
@.str.18 = [14 x i8] c"malloc failed\00"
@.str.19 = [43 x i8] c"only part of register set was written/read\00"
@.str.20 = [45 x i8] c"X register set not available for this thread\00"
@.str.21 = [29 x i8] c"unknown thread_db error '%d'\00"
define i8* @thread_db_err_str(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %26 [
i32 129, label %5
i32 142, label %6
i32 132, label %7
i32 133, label %8
i32 135, label %9
i32 147, label %10
i32 144, label %11
i32 146, label %12
i32 145, label %13
i32 148, label %14
i32 134, label %15
i32 137, label %16
i32 136, label %17
i32 138, label %18
i32 139, label %19
i32 143, label %20
i32 140, label %21
i32 131, label %22
i32 141, label %23
i32 128, label %24
i32 130, label %25
]
5: ; preds = %1
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %2
br label %29
6: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %29
7: ; preds = %1
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %29
8: ; preds = %1
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %29
9: ; preds = %1
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %29
10: ; preds = %1
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %29
11: ; preds = %1
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %29
12: ; preds = %1
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %29
13: ; preds = %1
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %29
14: ; preds = %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i8** %2
br label %29
15: ; preds = %1
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i8** %2
br label %29
16: ; preds = %1
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0), i8** %2
br label %29
17: ; preds = %1
store i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i8** %2
br label %29
18: ; preds = %1
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0), i8** %2
br label %29
19: ; preds = %1
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.14, i64 0, i64 0), i8** %2
br label %29
20: ; preds = %1
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.15, i64 0, i64 0), i8** %2
br label %29
21: ; preds = %1
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.16, i64 0, i64 0), i8** %2
br label %29
22: ; preds = %1
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.17, i64 0, i64 0), i8** %2
br label %29
23: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.18, i64 0, i64 0), i8** %2
br label %29
24: ; preds = %1
store i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.19, i64 0, i64 0), i8** %2
br label %29
25: ; preds = %1
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.20, i64 0, i64 0), i8** %2
br label %29
26: ; preds = %1
%27 = load i32, i32* %3
%28 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @thread_db_err_str.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.21, i64 0, i64 0), i32 %27)
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @thread_db_err_str.buf, i64 0, i64 0), i8** %2
br label %29
29: ; preds = %26, %25, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@thread_db_err_str.buf = internal global [64 x i8] zeroinitializer
@.str = [25 x i8] c"generic 'call succeeded'\00"
@.str.1 = [14 x i8] c"generic error\00"
@.str.2 = [27 x i8] c"no thread to satisfy query\00"
@.str.3 = [32 x i8] c"no sync handle to satisfy query\00"
@.str.4 = [24 x i8] c"no LWP to satisfy query\00"
@.str.5 = [23 x i8] c"invalid process handle\00"
@.str.6 = [22 x i8] c"invalid thread handle\00"
@.str.7 = [31 x i8] c"invalid synchronization handle\00"
@.str.8 = [21 x i8] c"invalid thread agent\00"
@.str.9 = [12 x i8] c"invalid key\00"
@.str.10 = [28 x i8] c"no event message for getmsg\00"
@.str.11 = [31 x i8] c"FPU register set not available\00"
@.str.12 = [38 x i8] c"application not linked with libthread\00"
@.str.13 = [33 x i8] c"requested event is not supported\00"
@.str.14 = [25 x i8] c"capability not available\00"
@.str.15 = [24 x i8] c"debugger service failed\00"
@.str.16 = [28 x i8] c"operation not applicable to\00"
@.str.17 = [40 x i8] c"no thread-specific data for this thread\00"
@.str.18 = [14 x i8] c"malloc failed\00"
@.str.19 = [43 x i8] c"only part of register set was written/read\00"
@.str.20 = [45 x i8] c"X register set not available for this thread\00"
@.str.21 = [29 x i8] c"unknown thread_db error '%d'\00"
@reltable.thread_db_err_str = [21 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([43 x i8]* @.str.19 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([45 x i8]* @.str.20 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([40 x i8]* @.str.17 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.2 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.3 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @.str.10 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.4 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([38 x i8]* @.str.12 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([31 x i8]* @.str.11 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([33 x i8]* @.str.13 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.14 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @.str.16 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.18 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.1 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.15 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.6 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.8 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([31 x i8]* @.str.7 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.5 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.9 to i64), i64 ptrtoint ([21 x i32]* @reltable.thread_db_err_str to i64)) to i32)]
define i8* @thread_db_err_str(i32 %0) {
%2 = add i32 %0, -128
%3 = icmp ult i32 %2, 21
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @thread_db_err_str.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.21, i64 0, i64 0), i32 %0)
br label %10
6: ; preds = %1
%7 = sext i32 %2 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([21 x i32]* @reltable.thread_db_err_str to i8*), i64 %8)
br label %10
10: ; preds = %6, %4
%11 = phi i8* [ getelementptr inbounds ([64 x i8], [64 x i8]* @thread_db_err_str.buf, i64 0, i64 0), %4 ], [ %9, %6 ]
ret i8* %11
}