#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 */
unsigned int clock_get(char *);
int cspi_get_divider(unsigned int data_rate) {
  unsigned int ipg_clk;
  int i;
  ipg_clk = clock_get("ipg");
  for (i = 0; i < 7; ++i) {
    if ((ipg_clk >> 2 + i) <= data_rate) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<cspi_get_divider>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    0xede(%rip),%rdi
call   1030 <clock_get@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x7,-0x10(%rbp)
jge    116d <cspi_get_divider+0x5d>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x2,%ecx
shr    %cl,%eax
cmp    -0x8(%rbp),%eax
ja     115a <cspi_get_divider+0x4a>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1174 <cspi_get_divider+0x64>
jmp    115f <cspi_get_divider+0x4f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1131 <cspi_get_divider+0x21>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cspi_get_divider>:
push   %rbx
mov    %edi,%ebx
lea    0xee6(%rip),%rdi
call   1030 <clock_get@plt>
mov    %eax,%edx
shr    $0x2,%edx
xor    %ecx,%ecx
cmp    %ebx,%edx
jbe    1182 <cspi_get_divider+0x72>
mov    %eax,%edx
shr    $0x3,%edx
mov    $0x1,%ecx
cmp    %ebx,%edx
jbe    1182 <cspi_get_divider+0x72>
mov    %eax,%edx
shr    $0x4,%edx
mov    $0x2,%ecx
cmp    %ebx,%edx
jbe    1182 <cspi_get_divider+0x72>
mov    %eax,%edx
shr    $0x5,%edx
mov    $0x3,%ecx
cmp    %ebx,%edx
jbe    1182 <cspi_get_divider+0x72>
mov    %eax,%edx
shr    $0x6,%edx
mov    $0x4,%ecx
cmp    %ebx,%edx
jbe    1182 <cspi_get_divider+0x72>
mov    %eax,%edx
shr    $0x7,%edx
mov    $0x5,%ecx
cmp    %ebx,%edx
jbe    1182 <cspi_get_divider+0x72>
shr    $0x8,%eax
cmp    %ebx,%eax
mov    $0xffffffff,%eax
mov    $0x6,%ecx
cmova  %eax,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"ipg\00"
define i32 @cspi_get_divider(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32 @clock_get(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %6, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %20, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 7
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = add nsw i32 2, %12
%14 = lshr i32 %11, %13
%15 = load i32, i32* %3
%16 = icmp ule i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = load i32, i32* %5
store i32 %18, i32* %2
br label %24
19: ; preds = %10
br label %20
20: ; preds = %19
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %7
23: ; preds = %7
store i32 -1, i32* %2
br label %24
24: ; preds = %23, %17
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [4 x i8] c"ipg\00"
define i32 @cspi_get_divider(i32 %0) {
%2 = tail call i32 @clock_get(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = lshr i32 %2, 2
%4 = icmp ugt i32 %3, %0
br i1 %4, label %5, label %24
5: ; preds = %1
%6 = lshr i32 %2, 3
%7 = icmp ugt i32 %6, %0
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = lshr i32 %2, 4
%10 = icmp ugt i32 %9, %0
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = lshr i32 %2, 5
%13 = icmp ugt i32 %12, %0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = lshr i32 %2, 6
%16 = icmp ugt i32 %15, %0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = lshr i32 %2, 7
%19 = icmp ugt i32 %18, %0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = lshr i32 %2, 8
%22 = icmp ugt i32 %21, %0
%23 = select i1 %22, i32 -1, i32 6
br label %24
24: ; preds = %20, %17, %14, %11, %8, %5, %1
%25 = phi i32 [ 0, %1 ], [ 1, %5 ], [ 2, %8 ], [ 3, %11 ], [ 4, %14 ], [ 5, %17 ], [ %23, %20 ]
ret i32 %25
}