#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_uplink_frame(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ demod_frame(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                               int /*<<< orphan*/);
int demod_uplink_frame(uint16_t *phi, uint8_t *to, int *rs_errors) {
  int16_t center_dphi;
  uint8_t interleaved[(((6) * ((576) + 160)) / 8)];
  if (!check_sync_word(phi, 0x153225B1DUL, &center_dphi)) {
    *rs_errors = 9999;
    return 0;
  }
  demod_frame(phi + (36) * 2, interleaved, (((6) * ((576) + 160)) / 8),
              center_dphi);
  if (correct_uplink_frame(interleaved, to, rs_errors) == 1)
    return (((6) * ((576) + 160)) + (36));
  else
    return 0;
}


x86 assembly (clang, -O0):
<demod_uplink_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8d0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x53225b1d,%esi
lea    -0x24(%rbp),%rdx
call   1050 <check_sync_word@plt>
cmp    $0x0,%eax
jne    1178 <demod_uplink_frame+0x48>
mov    -0x20(%rbp),%rax
movl   $0x270f,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11c7 <demod_uplink_frame+0x97>
mov    -0x10(%rbp),%rdi
add    $0x120,%rdi
lea    -0x8d0(%rbp),%rsi
mov    -0x24(%rbp),%ecx
mov    $0x228,%edx
call   1030 <demod_frame@plt>
lea    -0x8d0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <correct_uplink_frame@plt>
cmp    $0x1,%eax
jne    11c0 <demod_uplink_frame+0x90>
movl   $0x1164,-0x4(%rbp)
jmp    11c7 <demod_uplink_frame+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<demod_uplink_frame>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x8b8,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xc(%rsp),%rdx
mov    $0x53225b1d,%esi
call   1050 <check_sync_word@plt>
test   %eax,%eax
je     1197 <demod_uplink_frame+0x67>
add    $0x120,%rbx
mov    0xc(%rsp),%ecx
lea    0x10(%rsp),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x228,%edx
call   1030 <demod_frame@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <correct_uplink_frame@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
mov    $0x1164,%eax
cmovne %ecx,%eax
jmp    11a0 <demod_uplink_frame+0x70>
movl   $0x270f,(%r15)
xor    %eax,%eax
add    $0x8b8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @demod_uplink_frame(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [552 x 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 1394760477, 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 %28
15: ; preds = %3
%16 = load i32*, i32** %5
%17 = getelementptr inbounds i32, i32* %16, i64 72
%18 = getelementptr inbounds [552 x i32], [552 x i32]* %9, i64 0, i64 0
%19 = load i32, i32* %8
%20 = call i32 @demod_frame(i32* %17, i32* %18, i32 552, i32 %19)
%21 = getelementptr inbounds [552 x i32], [552 x i32]* %9, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = load i32*, i32** %7
%24 = call i32 @correct_uplink_frame(i32* %21, i32* %22, i32* %23)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %15
store i32 4452, i32* %4
br label %28
27: ; preds = %15
store i32 0, i32* %4
br label %28
28: ; preds = %27, %26, %13
%29 = load i32, i32* %4
ret i32 %29
}

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