#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*/ sprintf(char *, char *, unsigned char);
char *reset_code(unsigned char code) {
  static char buffer[25];
  if (code == 0x00 || (code & 0x80) == 0x80)
    return "DTE Originated";
  if (code == 0x03)
    return "Remote Procedure Error";
  if (code == 0x11)
    return "Incompatible Destination";
  if (code == 0x05)
    return "Local Procedure Error";
  if (code == 0x07)
    return "Network Congestion";
  sprintf(buffer, "Unknown %02X", code);
  return buffer;
}


x86 assembly (clang, -O0):
<reset_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x0,%eax
je     113f <reset_code+0x2f>
movzbl -0x9(%rbp),%eax
and    $0x80,%eax
cmp    $0x80,%eax
jne    114f <reset_code+0x3f>
lea    0xeba(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e5 <reset_code+0xd5>
movzbl -0x9(%rbp),%eax
cmp    $0x3,%eax
jne    116c <reset_code+0x5c>
lea    0xeac(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e5 <reset_code+0xd5>
movzbl -0x9(%rbp),%eax
cmp    $0x11,%eax
jne    1189 <reset_code+0x79>
lea    0xea6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e5 <reset_code+0xd5>
movzbl -0x9(%rbp),%eax
cmp    $0x5,%eax
jne    11a6 <reset_code+0x96>
lea    0xea2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e5 <reset_code+0xd5>
movzbl -0x9(%rbp),%eax
cmp    $0x7,%eax
jne    11c3 <reset_code+0xb3>
lea    0xe9b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e5 <reset_code+0xd5>
lea    0x2e76(%rip),%rdi
lea    0xe97(%rip),%rsi
movzbl -0x9(%rbp),%edx
call   1030 <sprintf@plt>
lea    0x2e5f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset_code>:
push   %rbx
test   %dil,%dil
jle    1148 <reset_code+0x38>
lea    -0x3(%rdi),%eax
ror    %al
cmp    $0x8,%al
jae    112c <reset_code+0x1c>
movzbl %al,%ecx
mov    $0x87,%edx
bt     %ecx,%edx
jb     1151 <reset_code+0x41>
movzbl %dil,%edx
lea    0x2f09(%rip),%rbx
lea    0xf2a(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
jmp    1163 <reset_code+0x53>
lea    0xeb1(%rip),%rbx
jmp    1163 <reset_code+0x53>
movsbq %al,%rax
lea    0xf1c(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@reset_code.buffer = internal global [25 x i8] zeroinitializer
@.str = [15 x i8] c"DTE Originated\00"
@.str.1 = [23 x i8] c"Remote Procedure Error\00"
@.str.2 = [25 x i8] c"Incompatible Destination\00"
@.str.3 = [22 x i8] c"Local Procedure Error\00"
@.str.4 = [19 x i8] c"Network Congestion\00"
@.str.5 = [13 x i8] c"Unknown %02X\00"
define i8* @reset_code(i8 zeroext %0) {
%2 = alloca i8*
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = zext i8 %4 to i32
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i8, i8* %3
%9 = zext i8 %8 to i32
%10 = and i32 %9, 128
%11 = icmp eq i32 %10, 128
br i1 %11, label %12, label %13
12: ; preds = %7, %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %2
br label %36
13: ; preds = %7
%14 = load i8, i8* %3
%15 = zext i8 %14 to i32
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %18
17: ; preds = %13
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %36
18: ; preds = %13
%19 = load i8, i8* %3
%20 = zext i8 %19 to i32
%21 = icmp eq i32 %20, 17
br i1 %21, label %22, label %23
22: ; preds = %18
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %36
23: ; preds = %18
%24 = load i8, i8* %3
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 5
br i1 %26, label %27, label %28
27: ; preds = %23
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %36
28: ; preds = %23
%29 = load i8, i8* %3
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 7
br i1 %31, label %32, label %33
32: ; preds = %28
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %36
33: ; preds = %28
%34 = load i8, i8* %3
%35 = call i32 @sprintf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @reset_code.buffer, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %34)
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @reset_code.buffer, i64 0, i64 0), i8** %2
br label %36
36: ; preds = %33, %32, %27, %22, %17, %12
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@reset_code.buffer = internal global [25 x i8] zeroinitializer
@.str = [15 x i8] c"DTE Originated\00"
@.str.1 = [23 x i8] c"Remote Procedure Error\00"
@.str.2 = [25 x i8] c"Incompatible Destination\00"
@.str.3 = [22 x i8] c"Local Procedure Error\00"
@.str.4 = [19 x i8] c"Network Congestion\00"
@.str.5 = [13 x i8] c"Unknown %02X\00"
@reltable.reset_code = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.reset_code to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.reset_code to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.reset_code to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.reset_code to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.reset_code to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.reset_code to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.reset_code to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.reset_code to i64)) to i32)]
define i8* @reset_code(i8 zeroext %0) {
%2 = icmp sgt i8 %0, 0
br i1 %2, label %3, label %17
3: ; preds = %1
%4 = add nsw i8 %0, -3
%5 = tail call i8 @llvm.fshl.i8(i8 %4, i8 %4, i8 7)
%6 = icmp ult i8 %5, 8
br i1 %6, label %9, label %7
7: ; preds = %9, %3
%8 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @reset_code.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %0)
br label %17
9: ; preds = %3
%10 = lshr i8 -121, %5
%11 = and i8 %10, 1
%12 = icmp eq i8 %11, 0
br i1 %12, label %7, label %13
13: ; preds = %9
%14 = sext i8 %5 to i64
%15 = shl i64 %14, 2
%16 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.reset_code to i8*), i64 %15)
br label %17
17: ; preds = %13, %1, %7
%18 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @reset_code.buffer, i64 0, i64 0), %7 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %1 ], [ %16, %13 ]
ret i8* %18
}