#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 */
int /*<<< orphan*/ strncpy(char *, char *, int);
void err_to_str(int error, char *buf, int maxlen) {
  char *str;
  switch (error) {
  case -1:
    str = "TRME_TOO_MANY_TRM";
    break;
  case -2:
    str = "TRME_DECODE_ERR";
    break;
  case -3:
    str = "TRME_SOCKET_FAILURE";
    break;
  case -5:
    str = "TRME_ALLOC_FAILURE";
    break;
  case -6:
    str = "TRME_FILE_ERROR";
    break;
  case -7:
    str = "TRME_OUT_OF_MEMORY";
    break;
  case -4:
    str = "TRME_NO_ACTIVE_SRVS";
    break;
  case -8:
    str = "TRME_OPTS_FAILURE";
    break;
  default:
    str = "Unknown error";
  }
  strncpy(buf, str, maxlen);
}


x86 assembly (clang, -O0):
<err_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x7,%eax
ja     11cb <err_to_str+0xbb>
mov    -0x28(%rbp),%rax
lea    0xebe(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xece(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d6 <err_to_str+0xc6>
lea    0xed0(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d6 <err_to_str+0xc6>
lea    0xed0(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d6 <err_to_str+0xc6>
lea    0xed4(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d6 <err_to_str+0xc6>
lea    0xed7(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d6 <err_to_str+0xc6>
lea    0xed7(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d6 <err_to_str+0xc6>
lea    0xeda(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d6 <err_to_str+0xc6>
lea    0xede(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d6 <err_to_str+0xc6>
lea    0xee0(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_to_str>:
mov    %rsi,%rax
cmp    $0xfffffff8,%edi
jb     1134 <err_to_str+0x24>
add    $0x8,%edi
movslq %edi,%rcx
lea    0xf7b(%rip),%rdi
movslq (%rdi,%rcx,4),%rsi
add    %rdi,%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0xf57(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"TRME_TOO_MANY_TRM\00"
@.str.1 = [16 x i8] c"TRME_DECODE_ERR\00"
@.str.2 = [20 x i8] c"TRME_SOCKET_FAILURE\00"
@.str.3 = [19 x i8] c"TRME_ALLOC_FAILURE\00"
@.str.4 = [16 x i8] c"TRME_FILE_ERROR\00"
@.str.5 = [19 x i8] c"TRME_OUT_OF_MEMORY\00"
@.str.6 = [20 x i8] c"TRME_NO_ACTIVE_SRVS\00"
@.str.7 = [18 x i8] c"TRME_OPTS_FAILURE\00"
@.str.8 = [14 x i8] c"Unknown error\00"
define void @err_to_str(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
switch i32 %8, label %17 [
i32 -1, label %9
i32 -2, label %10
i32 -3, label %11
i32 -5, label %12
i32 -6, label %13
i32 -7, label %14
i32 -4, label %15
i32 -8, label %16
]
9: ; preds = %3
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %7
br label %18
10: ; preds = %3
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %18
11: ; preds = %3
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %18
12: ; preds = %3
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %18
13: ; preds = %3
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %18
14: ; preds = %3
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %18
15: ; preds = %3
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8** %7
br label %18
16: ; preds = %3
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8** %7
br label %18
17: ; preds = %3
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %7
br label %18
18: ; preds = %17, %16, %15, %14, %13, %12, %11, %10, %9
%19 = load i8*, i8** %5
%20 = load i8*, i8** %7
%21 = load i32, i32* %6
%22 = call i32 @strncpy(i8* %19, i8* %20, i32 %21)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"TRME_TOO_MANY_TRM\00"
@.str.1 = [16 x i8] c"TRME_DECODE_ERR\00"
@.str.2 = [20 x i8] c"TRME_SOCKET_FAILURE\00"
@.str.3 = [19 x i8] c"TRME_ALLOC_FAILURE\00"
@.str.4 = [16 x i8] c"TRME_FILE_ERROR\00"
@.str.5 = [19 x i8] c"TRME_OUT_OF_MEMORY\00"
@.str.6 = [20 x i8] c"TRME_NO_ACTIVE_SRVS\00"
@.str.7 = [18 x i8] c"TRME_OPTS_FAILURE\00"
@.str.8 = [14 x i8] c"Unknown error\00"
@reltable.err_to_str = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.err_to_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.err_to_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.err_to_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.err_to_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.err_to_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.err_to_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.err_to_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.err_to_str to i64)) to i32)]
define void @err_to_str(i32 %0, i8* %1, i32 %2) {
%4 = icmp ugt i32 %0, -9
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = add i32 %0, 8
%7 = sext i32 %6 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.err_to_str to i8*), i64 %8)
br label %10
10: ; preds = %3, %5
%11 = phi i8* [ %9, %5 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), %3 ]
%12 = tail call i32 @strncpy(i8* %1, i8* %11, i32 %2)
ret void
}