#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 /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ deal_call_clr(unsigned char *, unsigned char *,
                                 int /*<<< orphan*/ *);
int /*<<< orphan*/ deal_echo(unsigned char *, unsigned char *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ deal_out_call(unsigned char *, unsigned char *,
                                 int /*<<< orphan*/ *);
int /*<<< orphan*/ deal_set_link_info(unsigned char *);
int /*<<< orphan*/ deal_start_ctrl_conn(unsigned char *, unsigned char *,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ deal_stop_ctrl_conn(unsigned char *, unsigned char *,
                                       int /*<<< orphan*/ *);
size_t read_pptp_header(int, unsigned char *, int *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int read_pptp_packet(int clientFd, unsigned char *packet,
                     unsigned char *rply_packet, ssize_t *rply_size) {
  size_t bytes_read;
  int pptp_ctrl_type;
  if ((bytes_read = read_pptp_header(clientFd, packet, &pptp_ctrl_type)) <= 0) {
    syslog(LOG_ERR, "CTRL: couldn't read packet header (%s)",
           bytes_read ? "retry" : "exit");
    return bytes_read;
  }
  switch (pptp_ctrl_type) {
  case 1:
    deal_start_ctrl_conn(packet, rply_packet, rply_size);
    break;
  case 3:
    deal_stop_ctrl_conn(packet, rply_packet, rply_size);
    break;
  case 7:
    deal_out_call(packet, rply_packet, rply_size);
    break;
  case 5:
    deal_echo(packet, rply_packet, rply_size);
    break;
  case 12:
    deal_call_clr(packet, rply_packet, rply_size);
    break;
  case 15:
    deal_set_link_info(packet);
    break;
  case 6:
  case 4:
  case 13:
    break;
  default:
    syslog(LOG_ERR, "CTRL: PPTP Control Message type %d not supported.",
           pptp_ctrl_type);
    pptp_ctrl_type = -1;
  }
  return pptp_ctrl_type;
}


x86 assembly (clang, -O0):
<read_pptp_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <read_pptp_header@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
ja     11f2 <read_pptp_packet+0x72>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rcx
lea    0xea0(%rip),%rdx
lea    0xe93(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    12c3 <read_pptp_packet+0x143>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0xe,%eax
ja     129c <read_pptp_packet+0x11c>
mov    -0x38(%rbp),%rax
lea    0xdee(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <deal_start_ctrl_conn@plt>
jmp    12bd <read_pptp_packet+0x13d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <deal_stop_ctrl_conn@plt>
jmp    12bd <read_pptp_packet+0x13d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <deal_out_call@plt>
jmp    12bd <read_pptp_packet+0x13d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   10a0 <deal_echo@plt>
jmp    12bd <read_pptp_packet+0x13d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <deal_call_clr@plt>
jmp    12bd <read_pptp_packet+0x13d>
mov    -0x10(%rbp),%rdi
call   1050 <deal_set_link_info@plt>
jmp    12bd <read_pptp_packet+0x13d>
jmp    12bd <read_pptp_packet+0x13d>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pptp_packet>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
lea    0xc(%rsp),%rdx
call   1040 <read_pptp_header@plt>
test   %rax,%rax
je     11d0 <read_pptp_packet+0x50>
mov    0xc(%rsp),%edx
lea    -0x1(%rdx),%eax
cmp    $0xe,%eax
ja     11f2 <read_pptp_packet+0x72>
lea    0xe4c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <deal_start_ctrl_conn@plt>
jmp    125b <read_pptp_packet+0xdb>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
lea    0xe7c(%rip),%rdx
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <syslog@plt>
jmp    125f <read_pptp_packet+0xdf>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
xor    %eax,%eax
call   1070 <syslog@plt>
movl   $0xffffffff,0xc(%rsp)
ff
jmp    125b <read_pptp_packet+0xdb>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1080 <deal_stop_ctrl_conn@plt>
jmp    125b <read_pptp_packet+0xdb>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   10a0 <deal_echo@plt>
jmp    125b <read_pptp_packet+0xdb>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <deal_out_call@plt>
jmp    125b <read_pptp_packet+0xdb>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1090 <deal_call_clr@plt>
jmp    125b <read_pptp_packet+0xdb>
mov    %rbx,%rdi
call   1050 <deal_set_link_info@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [39 x i8] c"CTRL: couldn't read packet header (%s)\00"
@.str.1 = [6 x i8] c"retry\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [50 x i8] c"CTRL: PPTP Control Message type %d not supported.\00"
define i32 @read_pptp_packet(i32 %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = call i64 @read_pptp_header(i32 %12, i8* %13, i32* %11)
store i64 %14, i64* %10
%15 = icmp ule i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %4
%17 = load i32, i32* @LOG_ERR
%18 = load i64, i64* %10
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%22 = call i32 (i32, i8*, ...) @syslog(i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i64, i64* %10
%24 = trunc i64 %23 to i32
store i32 %24, i32* %5
br label %62
25: ; preds = %4
%26 = load i32, i32* %11
switch i32 %26, label %56 [
i32 1, label %27
i32 3, label %32
i32 7, label %37
i32 5, label %42
i32 12, label %47
i32 15, label %52
i32 6, label %55
i32 4, label %55
i32 13, label %55
]
27: ; preds = %25
%28 = load i8*, i8** %7
%29 = load i8*, i8** %8
%30 = load i32*, i32** %9
%31 = call i32 @deal_start_ctrl_conn(i8* %28, i8* %29, i32* %30)
br label %60
32: ; preds = %25
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = load i32*, i32** %9
%36 = call i32 @deal_stop_ctrl_conn(i8* %33, i8* %34, i32* %35)
br label %60
37: ; preds = %25
%38 = load i8*, i8** %7
%39 = load i8*, i8** %8
%40 = load i32*, i32** %9
%41 = call i32 @deal_out_call(i8* %38, i8* %39, i32* %40)
br label %60
42: ; preds = %25
%43 = load i8*, i8** %7
%44 = load i8*, i8** %8
%45 = load i32*, i32** %9
%46 = call i32 @deal_echo(i8* %43, i8* %44, i32* %45)
br label %60
47: ; preds = %25
%48 = load i8*, i8** %7
%49 = load i8*, i8** %8
%50 = load i32*, i32** %9
%51 = call i32 @deal_call_clr(i8* %48, i8* %49, i32* %50)
br label %60
52: ; preds = %25
%53 = load i8*, i8** %7
%54 = call i32 @deal_set_link_info(i8* %53)
br label %60
55: ; preds = %25, %25, %25
br label %60
56: ; preds = %25
%57 = load i32, i32* @LOG_ERR
%58 = load i32, i32* %11
%59 = call i32 (i32, i8*, ...) @syslog(i32 %57, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %58)
store i32 -1, i32* %11
br label %60
60: ; preds = %56, %55, %52, %47, %42, %37, %32, %27
%61 = load i32, i32* %11
store i32 %61, i32* %5
br label %62
62: ; preds = %60, %16
%63 = load i32, i32* %5
ret i32 %63
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [39 x i8] c"CTRL: couldn't read packet header (%s)\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [50 x i8] c"CTRL: PPTP Control Message type %d not supported.\00"
define i32 @read_pptp_packet(i32 %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = call i64 @read_pptp_header(i32 %0, i8* %1, i32* %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* @LOG_ERR
%11 = call i32 (i32, i8*, ...) @syslog(i32 %10, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %31
12: ; preds = %4
%13 = load i32, i32* %5
switch i32 %13, label %26 [
i32 1, label %14
i32 3, label %16
i32 7, label %18
i32 5, label %20
i32 12, label %22
i32 15, label %24
i32 6, label %29
i32 4, label %29
i32 13, label %29
]
14: ; preds = %12
%15 = call i32 @deal_start_ctrl_conn(i8* %1, i8* %2, i32* %3)
br label %29
16: ; preds = %12
%17 = call i32 @deal_stop_ctrl_conn(i8* %1, i8* %2, i32* %3)
br label %29
18: ; preds = %12
%19 = call i32 @deal_out_call(i8* %1, i8* %2, i32* %3)
br label %29
20: ; preds = %12
%21 = call i32 @deal_echo(i8* %1, i8* %2, i32* %3)
br label %29
22: ; preds = %12
%23 = call i32 @deal_call_clr(i8* %1, i8* %2, i32* %3)
br label %29
24: ; preds = %12
%25 = call i32 @deal_set_link_info(i8* %1)
br label %29
26: ; preds = %12
%27 = load i32, i32* @LOG_ERR
%28 = call i32 (i32, i8*, ...) @syslog(i32 %27, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %13)
store i32 -1, i32* %5
br label %29
29: ; preds = %12, %12, %12, %26, %24, %22, %20, %18, %16, %14
%30 = load i32, i32* %5
br label %31
31: ; preds = %29, %9
%32 = phi i32 [ 0, %9 ], [ %30, %29 ]
ret i32 %32
}