#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*/ ov8858_eos_otp_write(int, int);
int ov8858_eos_update_awb_gain(int R_gain, int G_gain, int B_gain) {
  if (R_gain > 0x400) {
    ov8858_eos_otp_write(0x5018, R_gain >> 8);
    ov8858_eos_otp_write(0x5019, R_gain & 0x00ff);
  }
  if (G_gain > 0x400) {
    ov8858_eos_otp_write(0x501A, G_gain >> 8);
    ov8858_eos_otp_write(0x501B, G_gain & 0x00ff);
  }
  if (B_gain > 0x400) {
    ov8858_eos_otp_write(0x501C, B_gain >> 8);
    ov8858_eos_otp_write(0x501D, B_gain & 0x00ff);
  }
  return 0;
}


x86 assembly (clang, -O0):
<ov8858_eos_update_awb_gain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x400,-0x4(%rbp)
jle    1151 <ov8858_eos_update_awb_gain+0x41>
mov    -0x4(%rbp),%esi
sar    $0x8,%esi
mov    $0x5018,%edi
call   1030 <ov8858_eos_otp_write@plt>
mov    -0x4(%rbp),%esi
and    $0xff,%esi
mov    $0x5019,%edi
call   1030 <ov8858_eos_otp_write@plt>
cmpl   $0x400,-0x8(%rbp)
jle    1181 <ov8858_eos_update_awb_gain+0x71>
mov    -0x8(%rbp),%esi
sar    $0x8,%esi
mov    $0x501a,%edi
call   1030 <ov8858_eos_otp_write@plt>
mov    -0x8(%rbp),%esi
and    $0xff,%esi
mov    $0x501b,%edi
call   1030 <ov8858_eos_otp_write@plt>
cmpl   $0x400,-0xc(%rbp)
jle    11b1 <ov8858_eos_update_awb_gain+0xa1>
mov    -0xc(%rbp),%esi
sar    $0x8,%esi
mov    $0x501c,%edi
call   1030 <ov8858_eos_otp_write@plt>
mov    -0xc(%rbp),%esi
and    $0xff,%esi
mov    $0x501d,%edi
call   1030 <ov8858_eos_otp_write@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ov8858_eos_update_awb_gain>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
cmp    $0x401,%edi
jge    1157 <ov8858_eos_update_awb_gain+0x47>
cmp    $0x401,%ebp
jge    117d <ov8858_eos_update_awb_gain+0x6d>
cmp    $0x401,%r14d
jl     1150 <ov8858_eos_update_awb_gain+0x40>
mov    %r14d,%esi
shr    $0x8,%esi
mov    $0x501c,%edi
call   1030 <ov8858_eos_otp_write@plt>
movzbl %r14b,%esi
mov    $0x501d,%edi
call   1030 <ov8858_eos_otp_write@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %edi,%ebx
mov    %edi,%esi
shr    $0x8,%esi
mov    $0x5018,%edi
call   1030 <ov8858_eos_otp_write@plt>
movzbl %bl,%esi
mov    $0x5019,%edi
call   1030 <ov8858_eos_otp_write@plt>
cmp    $0x401,%ebp
jl     1129 <ov8858_eos_update_awb_gain+0x19>
mov    %ebp,%esi
shr    $0x8,%esi
mov    $0x501a,%edi
call   1030 <ov8858_eos_otp_write@plt>
movzbl %bpl,%esi
mov    $0x501b,%edi
call   1030 <ov8858_eos_otp_write@plt>
cmp    $0x401,%r14d
jge    1132 <ov8858_eos_update_awb_gain+0x22>
jmp    1150 <ov8858_eos_update_awb_gain+0x40>

LLVM IR (-O0):
define i32 @ov8858_eos_update_awb_gain(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 1024
br i1 %8, label %9, label %16
9: ; preds = %3
%10 = load i32, i32* %4
%11 = ashr i32 %10, 8
%12 = call i32 @ov8858_eos_otp_write(i32 20504, i32 %11)
%13 = load i32, i32* %4
%14 = and i32 %13, 255
%15 = call i32 @ov8858_eos_otp_write(i32 20505, i32 %14)
br label %16
16: ; preds = %9, %3
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 1024
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* %5
%21 = ashr i32 %20, 8
%22 = call i32 @ov8858_eos_otp_write(i32 20506, i32 %21)
%23 = load i32, i32* %5
%24 = and i32 %23, 255
%25 = call i32 @ov8858_eos_otp_write(i32 20507, i32 %24)
br label %26
26: ; preds = %19, %16
%27 = load i32, i32* %6
%28 = icmp sgt i32 %27, 1024
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* %6
%31 = ashr i32 %30, 8
%32 = call i32 @ov8858_eos_otp_write(i32 20508, i32 %31)
%33 = load i32, i32* %6
%34 = and i32 %33, 255
%35 = call i32 @ov8858_eos_otp_write(i32 20509, i32 %34)
br label %36
36: ; preds = %29, %26
ret i32 0
}

LLVM IR (-O2):
define i32 @ov8858_eos_update_awb_gain(i32 %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %0, 1024
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = lshr i32 %0, 8
%7 = tail call i32 @ov8858_eos_otp_write(i32 20504, i32 %6)
%8 = and i32 %0, 255
%9 = tail call i32 @ov8858_eos_otp_write(i32 20505, i32 %8)
br label %10
10: ; preds = %5, %3
%11 = icmp sgt i32 %1, 1024
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = lshr i32 %1, 8
%14 = tail call i32 @ov8858_eos_otp_write(i32 20506, i32 %13)
%15 = and i32 %1, 255
%16 = tail call i32 @ov8858_eos_otp_write(i32 20507, i32 %15)
br label %17
17: ; preds = %12, %10
%18 = icmp sgt i32 %2, 1024
br i1 %18, label %19, label %24
19: ; preds = %17
%20 = lshr i32 %2, 8
%21 = tail call i32 @ov8858_eos_otp_write(i32 20508, i32 %20)
%22 = and i32 %2, 255
%23 = tail call i32 @ov8858_eos_otp_write(i32 20509, i32 %22)
br label %24
24: ; preds = %19, %17
ret i32 0
}