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

/* Variables and functions */
int EINVAL;
int determine_path_rates_with_fir(unsigned long, unsigned long, unsigned long *,
                                  unsigned long *, int);
int ad9361_calculate_rf_clock_chain(unsigned long sample_rate,
                                    unsigned long rate_gov,
                                    unsigned long *rx_path_clks,
                                    unsigned long *tx_path_clks) {
  int ret, k;
  int FIR[] = {4, 2, 1};
  if (!((sample_rate) <= (61440000UL) ? (sample_rate) >= (25000000UL / 48)
                                      : false))
    return -EINVAL;
  for (k = 0; k < 3; k++) {
    ret = determine_path_rates_with_fir(sample_rate, rate_gov, rx_path_clks,
                                        tx_path_clks, FIR[k]);
    if (ret == 0)
      break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<ad9361_calculate_rf_clock_chain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0xed1(%rip),%rax
mov    %rax,-0x3c(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0x34(%rbp)
cmpq   $0x3a98000,-0x10(%rbp)
03
ja     115d <ad9361_calculate_rf_clock_chain+0x4d>
cmpq   $0x7f281,-0x10(%rbp)
jae    117f <ad9361_calculate_rf_clock_chain+0x6f>
jmp    116c <ad9361_calculate_rf_clock_chain+0x5c>
xor    %eax,%eax
test   $0x1,%al
jne    117f <ad9361_calculate_rf_clock_chain+0x6f>
jmp    116c <ad9361_calculate_rf_clock_chain+0x5c>
xor    %eax,%eax
mov    0x2e6b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11d9 <ad9361_calculate_rf_clock_chain+0xc9>
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x30(%rbp)
jge    11d3 <ad9361_calculate_rf_clock_chain+0xc3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
movslq -0x30(%rbp),%rax
mov    -0x3c(%rbp,%rax,4),%r8d
call   1030 <determine_path_rates_with_fir@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11c0 <ad9361_calculate_rf_clock_chain+0xb0>
jmp    11d3 <ad9361_calculate_rf_clock_chain+0xc3>
jmp    11c5 <ad9361_calculate_rf_clock_chain+0xb5>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1186 <ad9361_calculate_rf_clock_chain+0x76>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ad9361_calculate_rf_clock_chain>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    -0x7f281(%rdi),%rax
cmp    $0x3a18d7f,%rax
ja     117e <ad9361_calculate_rf_clock_chain+0x6e>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    $0x4,%r8d
call   1030 <determine_path_rates_with_fir@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     1189 <ad9361_calculate_rf_clock_chain+0x79>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    $0x2,%r8d
call   1030 <determine_path_rates_with_fir@plt>
test   %eax,%eax
je     1189 <ad9361_calculate_rf_clock_chain+0x79>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    $0x1,%r8d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <determine_path_rates_with_fir@plt>
mov    0x2e5b(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.ad9361_calculate_rf_clock_chain.FIR = [3 x i32] [i32 4, i32 2, i32 1]
@EINVAL = global i32 0
define i32 @ad9361_calculate_rf_clock_chain(i64 %0, i64 %1, i64* %2, i64* %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [3 x i32]
store i64 %0, i64* %6
store i64 %1, i64* %7
store i64* %2, i64** %8
store i64* %3, i64** %9
%13 = bitcast [3 x i32]* %12 to i8*
%14 = load i64, i64* %6
%15 = icmp ule i64 %14, 61440000
br i1 %15, label %16, label %19
16: ; preds = %4
%17 = load i64, i64* %6
%18 = icmp uge i64 %17, 520833
br i1 %18, label %23, label %20
19: ; preds = %4
br i1 false, label %23, label %20
20: ; preds = %19, %16
%21 = load i32, i32* @EINVAL
%22 = sub nsw i32 0, %21
store i32 %22, i32* %5
br label %46
23: ; preds = %19, %16
store i32 0, i32* %11
br label %24
24: ; preds = %41, %23
%25 = load i32, i32* %11
%26 = icmp slt i32 %25, 3
br i1 %26, label %27, label %44
27: ; preds = %24
%28 = load i64, i64* %6
%29 = load i64, i64* %7
%30 = load i64*, i64** %8
%31 = load i64*, i64** %9
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %12, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i32 @determine_path_rates_with_fir(i64 %28, i64 %29, i64* %30, i64* %31, i32 %35)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %27
br label %44
40: ; preds = %27
br label %41
41: ; preds = %40
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %24
44: ; preds = %39, %24
%45 = load i32, i32* %10
store i32 %45, i32* %5
br label %46
46: ; preds = %44, %20
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
@EINVAL = global i32 0
define i32 @ad9361_calculate_rf_clock_chain(i64 %0, i64 %1, i64* %2, i64* %3) {
%5 = add i64 %0, -520833
%6 = icmp ult i64 %5, 60919168
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @determine_path_rates_with_fir(i64 %0, i64 %1, i64* %2, i64* %3, i32 4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %18, label %13
10: ; preds = %4
%11 = load i32, i32* @EINVAL
%12 = sub nsw i32 0, %11
br label %18
13: ; preds = %7
%14 = tail call i32 @determine_path_rates_with_fir(i64 %0, i64 %1, i64* %2, i64* %3, i32 2)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 @determine_path_rates_with_fir(i64 %0, i64 %1, i64* %2, i64* %3, i32 1)
br label %18
18: ; preds = %16, %7, %13, %10
%19 = phi i32 [ %12, %10 ], [ 0, %7 ], [ 0, %13 ], [ %17, %16 ]
ret i32 %19
}