#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*/ strcmp(char const *, char *);
const char *simplify_cast_num(const char *cast, unsigned int val) {
  if (!strcmp(cast, "(u8)") && val < 0x100)
    return "";
  if (!strcmp(cast, "(s8)") && val < 0x80)
    return "";
  if (!strcmp(cast, "(u16)") && val < 0x10000)
    return "";
  if (!strcmp(cast, "(s16)") && val < 0x8000)
    return "";
  if (!strcmp(cast, "(s32)") && val < 0x80000000)
    return "";
  return cast;
}


x86 assembly (clang, -O0):
<simplify_cast_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed6(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1155 <simplify_cast_num+0x45>
cmpl   $0x100,-0x14(%rbp)
jae    1155 <simplify_cast_num+0x45>
lea    0xecf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <simplify_cast_num+0x125>
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    118b <simplify_cast_num+0x7b>
cmpl   $0x80,-0x14(%rbp)
jae    118b <simplify_cast_num+0x7b>
lea    0xe99(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <simplify_cast_num+0x125>
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11c1 <simplify_cast_num+0xb1>
cmpl   $0x10000,-0x14(%rbp)
jae    11c1 <simplify_cast_num+0xb1>
lea    0xe63(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <simplify_cast_num+0x125>
mov    -0x10(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11f7 <simplify_cast_num+0xe7>
cmpl   $0x8000,-0x14(%rbp)
jae    11f7 <simplify_cast_num+0xe7>
lea    0xe2d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <simplify_cast_num+0x125>
mov    -0x10(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    122d <simplify_cast_num+0x11d>
cmpl   $0x80000000,-0x14(%rbp)
jae    122d <simplify_cast_num+0x11d>
lea    0xdf7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <simplify_cast_num+0x125>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplify_cast_num>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xee0(%rip),%rsi
call   1030 <strcmp@plt>
lea    0xeef(%rip),%r14
cmp    $0xff,%ebp
ja     1138 <simplify_cast_num+0x28>
test   %eax,%eax
je     11a8 <simplify_cast_num+0x98>
lea    0xec6(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
cmp    $0x7f,%ebp
ja     1150 <simplify_cast_num+0x40>
test   %eax,%eax
je     11a8 <simplify_cast_num+0x98>
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
cmp    $0xffff,%ebp
ja     116b <simplify_cast_num+0x5b>
test   %eax,%eax
je     11a8 <simplify_cast_num+0x98>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
cmp    $0x7fff,%ebp
ja     1186 <simplify_cast_num+0x76>
test   %eax,%eax
je     11a8 <simplify_cast_num+0x98>
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
lea    0xe7d(%rip),%r14
cmovne %rbx,%r14
test   %ebp,%ebp
cmovs  %rbx,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"(u8)\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [5 x i8] c"(s8)\00"
@.str.3 = [6 x i8] c"(u16)\00"
@.str.4 = [6 x i8] c"(s16)\00"
@.str.5 = [6 x i8] c"(s32)\00"
define i8* @simplify_cast_num(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = call i32 @strcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp ult i32 %10, 256
br i1 %11, label %12, label %13
12: ; preds = %9
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %47
13: ; preds = %9, %2
%14 = load i8*, i8** %4
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i32, i32* %5
%19 = icmp ult i32 %18, 128
br i1 %19, label %20, label %21
20: ; preds = %17
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %47
21: ; preds = %17, %13
%22 = load i8*, i8** %4
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i32, i32* %5
%27 = icmp ult i32 %26, 65536
br i1 %27, label %28, label %29
28: ; preds = %25
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %47
29: ; preds = %25, %21
%30 = load i8*, i8** %4
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i32, i32* %5
%35 = icmp ult i32 %34, 32768
br i1 %35, label %36, label %37
36: ; preds = %33
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %47
37: ; preds = %33, %29
%38 = load i8*, i8** %4
%39 = call i32 @strcmp(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i32, i32* %5
%43 = icmp ult i32 %42, -2147483648
br i1 %43, label %44, label %45
44: ; preds = %41
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %47
45: ; preds = %41, %37
%46 = load i8*, i8** %4
store i8* %46, i8** %3
br label %47
47: ; preds = %45, %44, %36, %28, %20, %12
%48 = load i8*, i8** %3
ret i8* %48
}

LLVM IR (-O2):
@.str = [5 x i8] c"(u8)\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [5 x i8] c"(s8)\00"
@.str.3 = [6 x i8] c"(u16)\00"
@.str.4 = [6 x i8] c"(s16)\00"
@.str.5 = [6 x i8] c"(s32)\00"
define i8* @simplify_cast_num(i8* %0, i32 %1) {
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
%5 = icmp ult i32 %1, 256
%6 = and i1 %5, %4
br i1 %6, label %28, label %7
7: ; preds = %2
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
%10 = icmp ult i32 %1, 128
%11 = and i1 %10, %9
br i1 %11, label %28, label %12
12: ; preds = %7
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
%15 = icmp ult i32 %1, 65536
%16 = and i1 %15, %14
br i1 %16, label %28, label %17
17: ; preds = %12
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
%20 = icmp ult i32 %1, 32768
%21 = and i1 %20, %19
br i1 %21, label %28, label %22
22: ; preds = %17
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
%25 = icmp sgt i32 %1, -1
%26 = and i1 %25, %24
%27 = select i1 %26, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %0
br label %28
28: ; preds = %22, %17, %12, %7, %2
%29 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %12 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %17 ], [ %27, %22 ]
ret i8* %29
}