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

/* Variables and functions */
int ad9361_calculate_rf_clock_chain(unsigned long, int /*<<< orphan*/,
                                    unsigned long *, unsigned long *);
scalar_t__ check_result(unsigned long *, unsigned long *, unsigned long *,
                        unsigned long *);
int linux_calculate_rf_clock_chain(unsigned long, int /*<<< orphan*/,
                                   unsigned long *, unsigned long *);
int /*<<< orphan*/ set_fir_decint(unsigned long);
int main(void) {
  int ret, k;
  unsigned long rx1[6], tx1[6];
  unsigned long rx2[6], tx2[6];
  unsigned long sample_rate = 5208334;
  unsigned long max = 61440000;
  uint32_t rate_governor = 0;
  while (sample_rate <= max) {
    set_fir_decint(sample_rate);
    ret = linux_calculate_rf_clock_chain(sample_rate, rate_governor, rx1, tx1);
    if (ret < 0)
      return ret;
    ret = ad9361_calculate_rf_clock_chain(sample_rate, rate_governor, rx2, tx2);
    if (ret < 0)
      return ret;
    if (check_result(rx1, rx2, tx1, tx2))
      return -1;
    sample_rate++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x4f790e,-0xd8(%rbp)
movq   $0x3a98000,-0xe0(%rbp)
movl   $0x0,-0xe4(%rbp)
mov    -0xd8(%rbp),%rax
cmp    -0xe0(%rbp),%rax
ja     1244 <main+0x104>
mov    -0xd8(%rbp),%rdi
call   1060 <set_fir_decint@plt>
mov    -0xd8(%rbp),%rdi
mov    -0xe4(%rbp),%esi
lea    -0x40(%rbp),%rdx
lea    -0x70(%rbp),%rcx
call   1040 <linux_calculate_rf_clock_chain@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c4 <main+0x84>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124b <main+0x10b>
mov    -0xd8(%rbp),%rdi
mov    -0xe4(%rbp),%esi
lea    -0xa0(%rbp),%rdx
lea    -0xd0(%rbp),%rcx
call   1050 <ad9361_calculate_rf_clock_chain@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11fc <main+0xbc>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124b <main+0x10b>
lea    -0x40(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    -0xd0(%rbp),%rcx
call   1030 <check_result@plt>
cmp    $0x0,%rax
je     122d <main+0xed>
movl   $0xffffffff,-0x4(%rbp)
jmp    124b <main+0x10b>
mov    -0xd8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xd8(%rbp)
jmp    1172 <main+0x32>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc0,%rsp
mov    $0x4f790e,%ebx
lea    0x90(%rsp),%r14
lea    0x60(%rsp),%r15
lea    0x30(%rsp),%r12
mov    %rsp,%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <set_fir_decint@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <linux_calculate_rf_clock_chain@plt>
test   %eax,%eax
js     11cc <main+0x8c>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r12,%rdx
mov    %r13,%rcx
call   1050 <ad9361_calculate_rf_clock_chain@plt>
test   %eax,%eax
js     11cc <main+0x8c>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r13,%rcx
call   1030 <check_result@plt>
test   %rax,%rax
jne    11c7 <main+0x87>
add    $0x1,%rbx
cmp    $0x3a98001,%rbx
jne    1170 <main+0x30>
xor    %eax,%eax
jmp    11cc <main+0x8c>
mov    $0xffffffff,%eax
add    $0xc0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [6 x i64]
%5 = alloca [6 x i64]
%6 = alloca [6 x i64]
%7 = alloca [6 x i64]
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i32 0, i32* %1
store i64 5208334, i64* %8
store i64 61440000, i64* %9
store i32 0, i32* %10
br label %11
11: ; preds = %45, %0
%12 = load i64, i64* %8
%13 = load i64, i64* %9
%14 = icmp ule i64 %12, %13
br i1 %14, label %15, label %48
15: ; preds = %11
%16 = load i64, i64* %8
%17 = call i32 @set_fir_decint(i64 %16)
%18 = load i64, i64* %8
%19 = load i32, i32* %10
%20 = getelementptr inbounds [6 x i64], [6 x i64]* %4, i64 0, i64 0
%21 = getelementptr inbounds [6 x i64], [6 x i64]* %5, i64 0, i64 0
%22 = call i32 @linux_calculate_rf_clock_chain(i64 %18, i32 %19, i64* %20, i64* %21)
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %15
%26 = load i32, i32* %2
store i32 %26, i32* %1
br label %49
27: ; preds = %15
%28 = load i64, i64* %8
%29 = load i32, i32* %10
%30 = getelementptr inbounds [6 x i64], [6 x i64]* %6, i64 0, i64 0
%31 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 0
%32 = call i32 @ad9361_calculate_rf_clock_chain(i64 %28, i32 %29, i64* %30, i64* %31)
store i32 %32, i32* %2
%33 = load i32, i32* %2
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %27
%36 = load i32, i32* %2
store i32 %36, i32* %1
br label %49
37: ; preds = %27
%38 = getelementptr inbounds [6 x i64], [6 x i64]* %4, i64 0, i64 0
%39 = getelementptr inbounds [6 x i64], [6 x i64]* %6, i64 0, i64 0
%40 = getelementptr inbounds [6 x i64], [6 x i64]* %5, i64 0, i64 0
%41 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 0
%42 = call i64 @check_result(i64* %38, i64* %39, i64* %40, i64* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %37
store i32 -1, i32* %1
br label %49
45: ; preds = %37
%46 = load i64, i64* %8
%47 = add i64 %46, 1
store i64 %47, i64* %8
br label %11
48: ; preds = %11
store i32 0, i32* %1
br label %49
49: ; preds = %48, %44, %35, %25
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [6 x i64]
%2 = alloca [6 x i64]
%3 = alloca [6 x i64]
%4 = alloca [6 x i64]
%5 = bitcast [6 x i64]* %1 to i8*
%6 = bitcast [6 x i64]* %2 to i8*
%7 = bitcast [6 x i64]* %3 to i8*
%8 = bitcast [6 x i64]* %4 to i8*
%9 = getelementptr inbounds [6 x i64], [6 x i64]* %3, i64 0, i64 0
%10 = getelementptr inbounds [6 x i64], [6 x i64]* %4, i64 0, i64 0
%11 = getelementptr inbounds [6 x i64], [6 x i64]* %1, i64 0, i64 0
%12 = getelementptr inbounds [6 x i64], [6 x i64]* %2, i64 0, i64 0
br label %16
13: ; preds = %24
%14 = add nuw nsw i64 %17, 1
%15 = icmp eq i64 %14, 61440001
br i1 %15, label %27, label %16
16: ; preds = %0, %13
%17 = phi i64 [ 5208334, %0 ], [ %14, %13 ]
%18 = call i32 @set_fir_decint(i64 %17)
%19 = call i32 @linux_calculate_rf_clock_chain(i64 %17, i32 0, i64* %11, i64* %12)
%20 = icmp slt i32 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %16
%22 = call i32 @ad9361_calculate_rf_clock_chain(i64 %17, i32 0, i64* %9, i64* %10)
%23 = icmp slt i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = call i64 @check_result(i64* %11, i64* %9, i64* %12, i64* %10)
%26 = icmp eq i64 %25, 0
br i1 %26, label %13, label %27
27: ; preds = %13, %24, %21, %16
%28 = phi i32 [ %19, %16 ], [ %22, %21 ], [ -1, %24 ], [ 0, %13 ]
ret i32 %28
}