#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 /*<<< orphan*/ bbm_word_write(void *, int, unsigned short);
int /*<<< orphan*/ bbm_write(void *, int, int);
int /*<<< orphan*/ print_log(void *, char *, unsigned short);
signed int fci_i2c_init(void *handle, signed int speed, signed int slaveaddr) {
  unsigned short r = 24000 % (5 * speed);
  unsigned short pr = (24000 - r) / (5 * speed) - 1;
  if (((5 * speed) >> 1) <= r)
    pr++;
  bbm_word_write(handle, 0x0030, pr);
  bbm_write(handle, 0x0032, 0xc0);
  print_log(handle, "Internal I2C Pre-scale: 0x%02x\n", pr);
  return 0;
}


x86 assembly (clang, -O0):
<fci_i2c_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
imul   $0x5,-0xc(%rbp),%ecx
mov    $0x5dc0,%eax
cltd
idiv   %ecx
mov    %dx,%ax
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%ecx
mov    $0x5dc0,%eax
sub    %ecx,%eax
imul   $0x5,-0xc(%rbp),%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %ax,-0x14(%rbp)
imul   $0x5,-0xc(%rbp),%eax
sar    $0x1,%eax
movzwl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jg     118d <fci_i2c_init+0x5d>
mov    -0x14(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x30,%esi
movzwl -0x14(%rbp),%edx
call   1050 <bbm_word_write@plt>
mov    -0x8(%rbp),%rdi
mov    $0x32,%esi
mov    $0xc0,%edx
call   1040 <bbm_write@plt>
mov    -0x8(%rbp),%rdi
lea    0xe43(%rip),%rsi
movzwl -0x14(%rbp),%edx
call   1030 <print_log@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fci_i2c_init>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    (%rsi,%rsi,4),%ecx
mov    $0x5dc0,%eax
xor    %edx,%edx
idiv   %ecx
sar    %ecx
xor    %esi,%esi
cmp    %edx,%ecx
setg   %sil
sub    %esi,%eax
movzwl %ax,%ebp
mov    $0x30,%esi
mov    %ebp,%edx
call   1050 <bbm_word_write@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
mov    $0xc0,%edx
call   1040 <bbm_write@plt>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <print_log@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Internal I2C Pre-scale: 0x%02x\0A\00"
define i32 @fci_i2c_init(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i16
%8 = alloca i16
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = mul nsw i32 5, %9
%11 = srem i32 24000, %10
%12 = trunc i32 %11 to i16
store i16 %12, i16* %7
%13 = load i16, i16* %7
%14 = zext i16 %13 to i32
%15 = sub nsw i32 24000, %14
%16 = load i32, i32* %5
%17 = mul nsw i32 5, %16
%18 = sdiv i32 %15, %17
%19 = sub nsw i32 %18, 1
%20 = trunc i32 %19 to i16
store i16 %20, i16* %8
%21 = load i32, i32* %5
%22 = mul nsw i32 5, %21
%23 = ashr i32 %22, 1
%24 = load i16, i16* %7
%25 = zext i16 %24 to i32
%26 = icmp sle i32 %23, %25
br i1 %26, label %27, label %30
27: ; preds = %3
%28 = load i16, i16* %8
%29 = add i16 %28, 1
store i16 %29, i16* %8
br label %30
30: ; preds = %27, %3
%31 = load i8*, i8** %4
%32 = load i16, i16* %8
%33 = call i32 @bbm_word_write(i8* %31, i32 48, i16 zeroext %32)
%34 = load i8*, i8** %4
%35 = call i32 @bbm_write(i8* %34, i32 50, i32 192)
%36 = load i8*, i8** %4
%37 = load i16, i16* %8
%38 = call i32 @print_log(i8* %36, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i16 zeroext %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Internal I2C Pre-scale: 0x%02x\0A\00"
define i32 @fci_i2c_init(i8* %0, i32 %1, i32 %2) {
%4 = mul nsw i32 %1, 5
%5 = srem i32 24000, %4
%6 = sdiv i32 24000, %4
%7 = trunc i32 %6 to i16
%8 = ashr i32 %4, 1
%9 = icmp sgt i32 %8, %5
%10 = sext i1 %9 to i16
%11 = add nsw i16 %7, %10
%12 = tail call i32 @bbm_word_write(i8* %0, i32 48, i16 zeroext %11)
%13 = tail call i32 @bbm_write(i8* %0, i32 50, i32 192)
%14 = tail call i32 @print_log(i8* %0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i16 zeroext %11)
ret i32 0
}