#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;
struct payload {
  int dummy;
};
struct message {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ message_drop(struct message *, int, int /*<<< orphan*/, int,
                                int);
int message_validate_attribute(struct message *, struct payload *);
int message_validate_cert(struct message *, struct payload *);
int message_validate_cert_req(struct message *, struct payload *);
int message_validate_delete(struct message *, struct payload *);
int message_validate_hash(struct message *, struct payload *);
int message_validate_id(struct message *, struct payload *);
int message_validate_key_exch(struct message *, struct payload *);
int message_validate_nat_d(struct message *, struct payload *);
int message_validate_nat_oa(struct message *, struct payload *);
int message_validate_nonce(struct message *, struct payload *);
int message_validate_notify(struct message *, struct payload *);
int message_validate_proposal(struct message *, struct payload *);
int message_validate_sa(struct message *, struct payload *);
int message_validate_sig(struct message *, struct payload *);
int message_validate_transform(struct message *, struct payload *);
int message_validate_vendor(struct message *, struct payload *);
int message_validate_payload(struct message *m, struct payload *p,
                             u_int8_t payload) {
  switch (payload) {
  case 1:
    return message_validate_sa(m, p);
  case 2:
    return message_validate_proposal(m, p);
  case 3:
    return message_validate_transform(m, p);
  case 4:
    return message_validate_key_exch(m, p);
  case 5:
    return message_validate_id(m, p);
  case 6:
    return message_validate_cert(m, p);
  case 7:
    return message_validate_cert_req(m, p);
  case 8:
    return message_validate_hash(m, p);
  case 9:
    return message_validate_sig(m, p);
  case 10:
    return message_validate_nonce(m, p);
  case 11:
    return message_validate_notify(m, p);
  case 12:
    return message_validate_delete(m, p);
  case 13:
    return message_validate_vendor(m, p);
  case 14:
    return message_validate_attribute(m, p);
  case 20:
  case 130:
    return message_validate_nat_d(m, p);
  case 21:
  case 131:
    return message_validate_nat_oa(m, p);
  case 15:
  case 16:
  case 17:
  case 18:
  case 19:
  default:
    break;
  }
  message_drop(m, 1, 0, 1, 1);
  return -1;
}


x86 assembly (clang, -O0):
<message_validate_payload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x82,%eax
ja     13a3 <message_validate_payload+0x193>
mov    -0x28(%rbp),%rax
lea    0xdbb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <message_validate_sa@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10c0 <message_validate_proposal@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1110 <message_validate_transform@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10e0 <message_validate_key_exch@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <message_validate_id@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <message_validate_cert@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1120 <message_validate_cert_req@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <message_validate_hash@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <message_validate_sig@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <message_validate_nonce@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10d0 <message_validate_notify@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1100 <message_validate_delete@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <message_validate_vendor@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <message_validate_attribute@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1130 <message_validate_nat_d@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <message_validate_nat_oa@plt>
mov    %eax,-0x4(%rbp)
jmp    13c6 <message_validate_payload+0x1b6>
jmp    13a3 <message_validate_payload+0x193>
jmp    13a8 <message_validate_payload+0x198>
mov    -0x10(%rbp),%rdi
mov    $0x1,%r8d
xor    %edx,%edx
mov    %r8d,%esi
mov    %r8d,%ecx
call   10f0 <message_drop@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<message_validate_payload>:
push   %rax
add    $0xffffffff,%edx
cmp    $0x82,%edx
ja     128c <message_validate_payload+0x7c>
lea    0xddd(%rip),%rax
movslq (%rax,%rdx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
pop    %rax
jmp    1130 <message_validate_nat_d@plt>
pop    %rax
jmp    1060 <message_validate_nat_oa@plt>
pop    %rax
jmp    1070 <message_validate_sa@plt>
pop    %rax
jmp    10c0 <message_validate_proposal@plt>
pop    %rax
jmp    1110 <message_validate_transform@plt>
pop    %rax
jmp    10e0 <message_validate_key_exch@plt>
pop    %rax
jmp    1090 <message_validate_id@plt>
pop    %rax
jmp    10b0 <message_validate_cert@plt>
pop    %rax
jmp    1120 <message_validate_cert_req@plt>
pop    %rax
jmp    1080 <message_validate_hash@plt>
pop    %rax
jmp    1050 <message_validate_sig@plt>
pop    %rax
jmp    1040 <message_validate_nonce@plt>
pop    %rax
jmp    10d0 <message_validate_notify@plt>
pop    %rax
jmp    1100 <message_validate_delete@plt>
pop    %rax
jmp    10a0 <message_validate_vendor@plt>
pop    %rax
jmp    1030 <message_validate_attribute@plt>
mov    $0x1,%esi
xor    %edx,%edx
mov    $0x1,%ecx
mov    $0x1,%r8d
call   10f0 <message_drop@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.message = type { i32 }
%struct.payload = type { i32 }
define i32 @message_validate_payload(%struct.message* %0, %struct.payload* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.message*
%6 = alloca %struct.payload*
%7 = alloca i32
store %struct.message* %0, %struct.message** %5
store %struct.payload* %1, %struct.payload** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
switch i32 %8, label %74 [
i32 1, label %9
i32 2, label %13
i32 3, label %17
i32 4, label %21
i32 5, label %25
i32 6, label %29
i32 7, label %33
i32 8, label %37
i32 9, label %41
i32 10, label %45
i32 11, label %49
i32 12, label %53
i32 13, label %57
i32 14, label %61
i32 20, label %65
i32 130, label %65
i32 21, label %69
i32 131, label %69
i32 15, label %73
i32 16, label %73
i32 17, label %73
i32 18, label %73
i32 19, label %73
]
9: ; preds = %3
%10 = load %struct.message*, %struct.message** %5
%11 = load %struct.payload*, %struct.payload** %6
%12 = call i32 @message_validate_sa(%struct.message* %10, %struct.payload* %11)
store i32 %12, i32* %4
br label %78
13: ; preds = %3
%14 = load %struct.message*, %struct.message** %5
%15 = load %struct.payload*, %struct.payload** %6
%16 = call i32 @message_validate_proposal(%struct.message* %14, %struct.payload* %15)
store i32 %16, i32* %4
br label %78
17: ; preds = %3
%18 = load %struct.message*, %struct.message** %5
%19 = load %struct.payload*, %struct.payload** %6
%20 = call i32 @message_validate_transform(%struct.message* %18, %struct.payload* %19)
store i32 %20, i32* %4
br label %78
21: ; preds = %3
%22 = load %struct.message*, %struct.message** %5
%23 = load %struct.payload*, %struct.payload** %6
%24 = call i32 @message_validate_key_exch(%struct.message* %22, %struct.payload* %23)
store i32 %24, i32* %4
br label %78
25: ; preds = %3
%26 = load %struct.message*, %struct.message** %5
%27 = load %struct.payload*, %struct.payload** %6
%28 = call i32 @message_validate_id(%struct.message* %26, %struct.payload* %27)
store i32 %28, i32* %4
br label %78
29: ; preds = %3
%30 = load %struct.message*, %struct.message** %5
%31 = load %struct.payload*, %struct.payload** %6
%32 = call i32 @message_validate_cert(%struct.message* %30, %struct.payload* %31)
store i32 %32, i32* %4
br label %78
33: ; preds = %3
%34 = load %struct.message*, %struct.message** %5
%35 = load %struct.payload*, %struct.payload** %6
%36 = call i32 @message_validate_cert_req(%struct.message* %34, %struct.payload* %35)
store i32 %36, i32* %4
br label %78
37: ; preds = %3
%38 = load %struct.message*, %struct.message** %5
%39 = load %struct.payload*, %struct.payload** %6
%40 = call i32 @message_validate_hash(%struct.message* %38, %struct.payload* %39)
store i32 %40, i32* %4
br label %78
41: ; preds = %3
%42 = load %struct.message*, %struct.message** %5
%43 = load %struct.payload*, %struct.payload** %6
%44 = call i32 @message_validate_sig(%struct.message* %42, %struct.payload* %43)
store i32 %44, i32* %4
br label %78
45: ; preds = %3
%46 = load %struct.message*, %struct.message** %5
%47 = load %struct.payload*, %struct.payload** %6
%48 = call i32 @message_validate_nonce(%struct.message* %46, %struct.payload* %47)
store i32 %48, i32* %4
br label %78
49: ; preds = %3
%50 = load %struct.message*, %struct.message** %5
%51 = load %struct.payload*, %struct.payload** %6
%52 = call i32 @message_validate_notify(%struct.message* %50, %struct.payload* %51)
store i32 %52, i32* %4
br label %78
53: ; preds = %3
%54 = load %struct.message*, %struct.message** %5
%55 = load %struct.payload*, %struct.payload** %6
%56 = call i32 @message_validate_delete(%struct.message* %54, %struct.payload* %55)
store i32 %56, i32* %4
br label %78
57: ; preds = %3
%58 = load %struct.message*, %struct.message** %5
%59 = load %struct.payload*, %struct.payload** %6
%60 = call i32 @message_validate_vendor(%struct.message* %58, %struct.payload* %59)
store i32 %60, i32* %4
br label %78
61: ; preds = %3
%62 = load %struct.message*, %struct.message** %5
%63 = load %struct.payload*, %struct.payload** %6
%64 = call i32 @message_validate_attribute(%struct.message* %62, %struct.payload* %63)
store i32 %64, i32* %4
br label %78
65: ; preds = %3, %3
%66 = load %struct.message*, %struct.message** %5
%67 = load %struct.payload*, %struct.payload** %6
%68 = call i32 @message_validate_nat_d(%struct.message* %66, %struct.payload* %67)
store i32 %68, i32* %4
br label %78
69: ; preds = %3, %3
%70 = load %struct.message*, %struct.message** %5
%71 = load %struct.payload*, %struct.payload** %6
%72 = call i32 @message_validate_nat_oa(%struct.message* %70, %struct.payload* %71)
store i32 %72, i32* %4
br label %78
73: ; preds = %3, %3, %3, %3, %3
br label %74
74: ; preds = %3, %73
br label %75
75: ; preds = %74
%76 = load %struct.message*, %struct.message** %5
%77 = call i32 @message_drop(%struct.message* %76, i32 1, i32 0, i32 1, i32 1)
store i32 -1, i32* %4
br label %78
78: ; preds = %75, %69, %65, %61, %57, %53, %49, %45, %41, %37, %33, %29, %25, %21, %17, %13, %9
%79 = load i32, i32* %4
ret i32 %79
}

LLVM IR (-O2):
%struct.message = type { i32 }
%struct.payload = type { i32 }
define i32 @message_validate_payload(%struct.message* %0, %struct.payload* %1, i32 %2) {
switch i32 %2, label %36 [
i32 1, label %4
i32 2, label %6
i32 3, label %8
i32 4, label %10
i32 5, label %12
i32 6, label %14
i32 7, label %16
i32 8, label %18
i32 9, label %20
i32 10, label %22
i32 11, label %24
i32 12, label %26
i32 13, label %28
i32 14, label %30
i32 20, label %32
i32 130, label %32
i32 21, label %34
i32 131, label %34
]
4: ; preds = %3
%5 = tail call i32 @message_validate_sa(%struct.message* %0, %struct.payload* %1)
br label %38
6: ; preds = %3
%7 = tail call i32 @message_validate_proposal(%struct.message* %0, %struct.payload* %1)
br label %38
8: ; preds = %3
%9 = tail call i32 @message_validate_transform(%struct.message* %0, %struct.payload* %1)
br label %38
10: ; preds = %3
%11 = tail call i32 @message_validate_key_exch(%struct.message* %0, %struct.payload* %1)
br label %38
12: ; preds = %3
%13 = tail call i32 @message_validate_id(%struct.message* %0, %struct.payload* %1)
br label %38
14: ; preds = %3
%15 = tail call i32 @message_validate_cert(%struct.message* %0, %struct.payload* %1)
br label %38
16: ; preds = %3
%17 = tail call i32 @message_validate_cert_req(%struct.message* %0, %struct.payload* %1)
br label %38
18: ; preds = %3
%19 = tail call i32 @message_validate_hash(%struct.message* %0, %struct.payload* %1)
br label %38
20: ; preds = %3
%21 = tail call i32 @message_validate_sig(%struct.message* %0, %struct.payload* %1)
br label %38
22: ; preds = %3
%23 = tail call i32 @message_validate_nonce(%struct.message* %0, %struct.payload* %1)
br label %38
24: ; preds = %3
%25 = tail call i32 @message_validate_notify(%struct.message* %0, %struct.payload* %1)
br label %38
26: ; preds = %3
%27 = tail call i32 @message_validate_delete(%struct.message* %0, %struct.payload* %1)
br label %38
28: ; preds = %3
%29 = tail call i32 @message_validate_vendor(%struct.message* %0, %struct.payload* %1)
br label %38
30: ; preds = %3
%31 = tail call i32 @message_validate_attribute(%struct.message* %0, %struct.payload* %1)
br label %38
32: ; preds = %3, %3
%33 = tail call i32 @message_validate_nat_d(%struct.message* %0, %struct.payload* %1)
br label %38
34: ; preds = %3, %3
%35 = tail call i32 @message_validate_nat_oa(%struct.message* %0, %struct.payload* %1)
br label %38
36: ; preds = %3
%37 = tail call i32 @message_drop(%struct.message* %0, i32 1, i32 0, i32 1, i32 1)
br label %38
38: ; preds = %36, %34, %32, %30, %28, %26, %24, %22, %20, %18, %16, %14, %12, %10, %8, %6, %4
%39 = phi i32 [ -1, %36 ], [ %35, %34 ], [ %33, %32 ], [ %31, %30 ], [ %29, %28 ], [ %27, %26 ], [ %25, %24 ], [ %23, %22 ], [ %21, %20 ], [ %19, %18 ], [ %17, %16 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ], [ %5, %4 ]
ret i32 %39
}