#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*/ uint8_t;
typedef int /*<<< orphan*/ uint16_t;
typedef int /*<<< orphan*/ int16_t;

/* Variables and functions */
int /*<<< orphan*/ check_sync_word(int /*<<< orphan*/ *, int,
                                   int /*<<< orphan*/ *);
int correct_adsb_frame(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ demod_frame(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                               int /*<<< orphan*/);
int demod_adsb_frame(uint16_t *phi, uint8_t *to, int *rs_errors) {
  int16_t center_dphi;
  int frametype;
  if (!check_sync_word(phi, 0xEACDDA4E2UL, &center_dphi)) {
    *rs_errors = 9999;
    return 0;
  }
  demod_frame(phi + (36) * 2, to, (((272) + 112) / 8), center_dphi);
  frametype = correct_adsb_frame(to, rs_errors);
  if (frametype == 1)
    return ((36) + ((144) + 96));
  else if (frametype == 2)
    return ((36) + ((272) + 112));
  else
    return 0;
}


x86 assembly (clang, -O0):
<demod_adsb_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xacdda4e2,%esi
lea    -0x24(%rbp),%rdx
call   1050 <check_sync_word@plt>
cmp    $0x0,%eax
jne    1175 <demod_adsb_frame+0x45>
mov    -0x20(%rbp),%rax
movl   $0x270f,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d4 <demod_adsb_frame+0xa4>
mov    -0x10(%rbp),%rdi
add    $0x120,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%ecx
mov    $0x30,%edx
call   1030 <demod_frame@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <correct_adsb_frame@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jne    11b7 <demod_adsb_frame+0x87>
movl   $0x114,-0x4(%rbp)
jmp    11d4 <demod_adsb_frame+0xa4>
cmpl   $0x2,-0x28(%rbp)
jne    11cd <demod_adsb_frame+0x9d>
movl   $0x1a4,-0x4(%rbp)
jmp    11d4 <demod_adsb_frame+0xa4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<demod_adsb_frame>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xc(%rsp),%rdx
mov    $0xacdda4e2,%esi
call   1050 <check_sync_word@plt>
test   %eax,%eax
je     1195 <demod_adsb_frame+0x65>
add    $0x120,%rbx
mov    0xc(%rsp),%ecx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x30,%edx
call   1030 <demod_frame@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <correct_adsb_frame@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
mov    $0x1a4,%edx
cmovne %ecx,%edx
cmp    $0x1,%eax
mov    $0x114,%eax
cmovne %edx,%eax
jmp    119e <demod_adsb_frame+0x6e>
movl   $0x270f,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @demod_adsb_frame(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%10 = load i32*, i32** %5
%11 = call i32 @check_sync_word(i32* %10, i32 -1394760478, i32* %8)
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = load i32*, i32** %7
store i32 9999, i32* %14
store i32 0, i32* %4
br label %32
15: ; preds = %3
%16 = load i32*, i32** %5
%17 = getelementptr inbounds i32, i32* %16, i64 72
%18 = load i32*, i32** %6
%19 = load i32, i32* %8
%20 = call i32 @demod_frame(i32* %17, i32* %18, i32 48, i32 %19)
%21 = load i32*, i32** %6
%22 = load i32*, i32** %7
%23 = call i32 @correct_adsb_frame(i32* %21, i32* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %15
store i32 276, i32* %4
br label %32
27: ; preds = %15
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, 2
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 420, i32* %4
br label %32
31: ; preds = %27
store i32 0, i32* %4
br label %32
32: ; preds = %31, %30, %26, %13
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @demod_adsb_frame(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 @check_sync_word(i32* %0, i32 -1394760478, i32* %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %3
store i32 9999, i32* %2
br label %18
9: ; preds = %3
%10 = getelementptr inbounds i32, i32* %0, i64 72
%11 = load i32, i32* %4
%12 = call i32 @demod_frame(i32* %10, i32* %1, i32 48, i32 %11)
%13 = call i32 @correct_adsb_frame(i32* %1, i32* %2)
%14 = icmp eq i32 %13, 2
%15 = select i1 %14, i32 420, i32 0
%16 = icmp eq i32 %13, 1
%17 = select i1 %16, i32 276, i32 %15
br label %18
18: ; preds = %9, %8
%19 = phi i32 [ 0, %8 ], [ %17, %9 ]
ret i32 %19
}