#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 u_int8_t;

/* Variables and functions */
int ipsec_validate_transform_id(u_int8_t proto, u_int8_t transform_id) {
  switch (proto) {
  default:
  case 1:
    return transform_id != 1;
  case 2:
    return transform_id < 2 || transform_id > 8 ? -1 : 0;
  case 3:
    return transform_id < 1 || (transform_id > 23 && transform_id < 249) ||
                   transform_id > 253
               ? -1
               : 0;
  case 4:
    return transform_id < 1 || transform_id > 4 ? -1 : 0;
  }
}


x86 assembly (clang, -O0):
<ipsec_validate_transform_id>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     1133 <ipsec_validate_transform_id+0x33>
mov    -0x18(%rbp),%rax
lea    0xed6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    1138 <ipsec_validate_transform_id+0x38>
cmpl   $0x1,-0xc(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11f9 <ipsec_validate_transform_id+0xf9>
mov    $0x1,%al
cmpl   $0x2,-0xc(%rbp)
mov    %al,-0x19(%rbp)
jl     1165 <ipsec_validate_transform_id+0x65>
cmpl   $0x8,-0xc(%rbp)
setg   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%dl
xor    %eax,%eax
mov    $0xffffffff,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11f9 <ipsec_validate_transform_id+0xf9>
mov    $0x1,%al
cmpl   $0x1,-0xc(%rbp)
mov    %al,-0x1a(%rbp)
jl     11b5 <ipsec_validate_transform_id+0xb5>
cmpl   $0x17,-0xc(%rbp)
jle    11a8 <ipsec_validate_transform_id+0xa8>
mov    $0x1,%al
cmpl   $0xf9,-0xc(%rbp)
mov    %al,-0x1a(%rbp)
jl     11b5 <ipsec_validate_transform_id+0xb5>
cmpl   $0xfd,-0xc(%rbp)
setg   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%dl
xor    %eax,%eax
mov    $0xffffffff,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11f9 <ipsec_validate_transform_id+0xf9>
mov    $0x1,%al
cmpl   $0x1,-0xc(%rbp)
mov    %al,-0x1b(%rbp)
jl     11e6 <ipsec_validate_transform_id+0xe6>
cmpl   $0x4,-0xc(%rbp)
setg   %al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%dl
xor    %eax,%eax
mov    $0xffffffff,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipsec_validate_transform_id>:
cmp    $0x2,%edi
je     1118 <ipsec_validate_transform_id+0x18>
cmp    $0x3,%edi
je     1121 <ipsec_validate_transform_id+0x21>
cmp    $0x4,%edi
jne    1143 <ipsec_validate_transform_id+0x43>
add    $0xfffffffb,%esi
cmp    $0xfffffffc,%esi
sbb    %eax,%eax
ret
add    $0xfffffff7,%esi
cmp    $0xfffffff9,%esi
sbb    %eax,%eax
ret
lea    -0x18(%rsi),%eax
cmp    $0xe1,%eax
setb   %al
add    $0xffffff02,%esi
cmp    $0xffffff03,%esi
setb   %cl
or     %al,%cl
movzbl %cl,%eax
neg    %eax
ret
xor    %eax,%eax
cmp    $0x1,%esi
setne  %al
ret

LLVM IR (-O0):
define i32 @ipsec_validate_transform_id(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
switch i32 %6, label %7 [
i32 1, label %8
i32 2, label %12
i32 3, label %22
i32 4, label %38
]
7: ; preds = %2
br label %8
8: ; preds = %2, %7
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 1
%11 = zext i1 %10 to i32
store i32 %11, i32* %3
br label %48
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 2
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 8
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ true, %12 ], [ %17, %15 ]
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 -1, i32 0
store i32 %21, i32* %3
br label %48
22: ; preds = %2
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 1
br i1 %24, label %34, label %25
25: ; preds = %22
%26 = load i32, i32* %5
%27 = icmp sgt i32 %26, 23
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %5
%30 = icmp slt i32 %29, 249
br i1 %30, label %34, label %31
31: ; preds = %28, %25
%32 = load i32, i32* %5
%33 = icmp sgt i32 %32, 253
br label %34
34: ; preds = %31, %28, %22
%35 = phi i1 [ true, %28 ], [ true, %22 ], [ %33, %31 ]
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 -1, i32 0
store i32 %37, i32* %3
br label %48
38: ; preds = %2
%39 = load i32, i32* %5
%40 = icmp slt i32 %39, 1
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load i32, i32* %5
%43 = icmp sgt i32 %42, 4
br label %44
44: ; preds = %41, %38
%45 = phi i1 [ true, %38 ], [ %43, %41 ]
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 -1, i32 0
store i32 %47, i32* %3
br label %48
48: ; preds = %44, %34, %18, %8
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
define i32 @ipsec_validate_transform_id(i32 %0, i32 %1) {
switch i32 %0, label %3 [
i32 4, label %17
i32 2, label %6
i32 3, label %10
]
3: ; preds = %2
%4 = icmp ne i32 %1, 1
%5 = zext i1 %4 to i32
br label %21
6: ; preds = %2
%7 = add i32 %1, -9
%8 = icmp ult i32 %7, -7
%9 = sext i1 %8 to i32
br label %21
10: ; preds = %2
%11 = add i32 %1, -24
%12 = icmp ult i32 %11, 225
%13 = add i32 %1, -254
%14 = icmp ult i32 %13, -253
%15 = or i1 %14, %12
%16 = sext i1 %15 to i32
br label %21
17: ; preds = %2
%18 = add i32 %1, -5
%19 = icmp ult i32 %18, -4
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %17, %10, %6, %3
%22 = phi i32 [ %5, %3 ], [ %16, %10 ], [ %9, %6 ], [ %20, %17 ]
ret i32 %22
}