#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*/ mdelay(int);
int ov5648_rio4g_my_otp_read(int);
int /*<<< orphan*/ ov5648_rio4g_my_otp_write(int, int);
int ov5648_rio4g_check_otp(int index) {
  int flag, i;
  int rg, bg;
  if (index == 1) {
    ov5648_rio4g_my_otp_write(0x3d84, 0xc0);
    ov5648_rio4g_my_otp_write(0x3d85, 0x00);
    ov5648_rio4g_my_otp_write(0x3d86, 0x0f);
    ov5648_rio4g_my_otp_write(0x3d81, 0x01);
    mdelay(5);
    flag = ov5648_rio4g_my_otp_read(0x3d05);
    rg = ov5648_rio4g_my_otp_read(0x3d07);
    bg = ov5648_rio4g_my_otp_read(0x3d08);
  } else if (index == 2) {
    ov5648_rio4g_my_otp_write(0x3d84, 0xc0);
    ov5648_rio4g_my_otp_write(0x3d85, 0x00);
    ov5648_rio4g_my_otp_write(0x3d86, 0x0f);
    ov5648_rio4g_my_otp_write(0x3d81, 0x01);
    mdelay(5);
    flag = ov5648_rio4g_my_otp_read(0x3d0e);
    ov5648_rio4g_my_otp_write(0x3d84, 0xc0);
    ov5648_rio4g_my_otp_write(0x3d85, 0x10);
    ov5648_rio4g_my_otp_write(0x3d86, 0x1f);
    ov5648_rio4g_my_otp_write(0x3d81, 0x01);
    mdelay(5);
    rg = ov5648_rio4g_my_otp_read(0x3d00);
    bg = ov5648_rio4g_my_otp_read(0x3d01);
  } else if (index == 3) {
    ov5648_rio4g_my_otp_write(0x3d84, 0xc0);
    ov5648_rio4g_my_otp_write(0x3d85, 0x10);
    ov5648_rio4g_my_otp_write(0x3d86, 0x1f);
    ov5648_rio4g_my_otp_write(0x3d81, 0x01);
    mdelay(5);
    flag = ov5648_rio4g_my_otp_read(0x3d07);
    rg = ov5648_rio4g_my_otp_read(0x3d09);
    bg = ov5648_rio4g_my_otp_read(0x3d0a);
  }
  flag = flag & 0x80;
  for (i = 0; i < 16; i++) {
    ov5648_rio4g_my_otp_write(0x3d00 + i, 0x00);
  }
  if (flag) {
    return 1;
  } else {
    if (rg == 0 && bg == 0) {
      return 0;
    } else {
      return 2;
    }
  }
}


x86 assembly (clang, -O0):
<ov5648_rio4g_check_otp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11b4 <ov5648_rio4g_check_otp+0x84>
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d85,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d86,%edi
mov    $0xf,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x5,%edi
call   1030 <mdelay@plt>
mov    $0x3d05,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,-0xc(%rbp)
mov    $0x3d07,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,-0x14(%rbp)
mov    $0x3d08,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,-0x18(%rbp)
jmp    12f4 <ov5648_rio4g_check_otp+0x1c4>
cmpl   $0x2,-0x8(%rbp)
jne    1273 <ov5648_rio4g_check_otp+0x143>
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d85,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d86,%edi
mov    $0xf,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x5,%edi
call   1030 <mdelay@plt>
mov    $0x3d0e,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,-0xc(%rbp)
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d85,%edi
mov    $0x10,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d86,%edi
mov    $0x1f,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x5,%edi
call   1030 <mdelay@plt>
mov    $0x3d00,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,-0x14(%rbp)
mov    $0x3d01,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,-0x18(%rbp)
jmp    12ef <ov5648_rio4g_check_otp+0x1bf>
cmpl   $0x3,-0x8(%rbp)
jne    12ea <ov5648_rio4g_check_otp+0x1ba>
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d85,%edi
mov    $0x10,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d86,%edi
mov    $0x1f,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x5,%edi
call   1030 <mdelay@plt>
mov    $0x3d07,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,-0xc(%rbp)
mov    $0x3d09,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,-0x14(%rbp)
mov    $0x3d0a,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,-0x18(%rbp)
jmp    12ef <ov5648_rio4g_check_otp+0x1bf>
jmp    12f4 <ov5648_rio4g_check_otp+0x1c4>
mov    -0xc(%rbp),%eax
and    $0x80,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x10,-0x10(%rbp)
jge    132e <ov5648_rio4g_check_otp+0x1fe>
mov    -0x10(%rbp),%edi
add    $0x3d00,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1306 <ov5648_rio4g_check_otp+0x1d6>
cmpl   $0x0,-0xc(%rbp)
je     1344 <ov5648_rio4g_check_otp+0x214>
movl   $0x1,-0x4(%rbp)
jmp    136b <ov5648_rio4g_check_otp+0x23b>
cmpl   $0x0,-0x14(%rbp)
jne    1364 <ov5648_rio4g_check_otp+0x234>
cmpl   $0x0,-0x18(%rbp)
jne    1364 <ov5648_rio4g_check_otp+0x234>
movl   $0x0,-0x4(%rbp)
jmp    136b <ov5648_rio4g_check_otp+0x23b>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ov5648_rio4g_check_otp>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%edi
je     11aa <ov5648_rio4g_check_otp+0x7a>
cmp    $0x2,%edi
je     120c <ov5648_rio4g_check_otp+0xdc>
cmp    $0x1,%edi
jne    12c6 <ov5648_rio4g_check_otp+0x196>
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d85,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d86,%edi
mov    $0xf,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x5,%edi
call   1030 <mdelay@plt>
mov    $0x3d05,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,%r14d
mov    $0x3d08,%ebp
mov    $0x3d07,%edi
jmp    12ac <ov5648_rio4g_check_otp+0x17c>
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d85,%edi
mov    $0x10,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d86,%edi
mov    $0x1f,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x5,%edi
call   1030 <mdelay@plt>
mov    $0x3d07,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,%r14d
mov    $0x3d0a,%ebp
mov    $0x3d09,%edi
jmp    12ac <ov5648_rio4g_check_otp+0x17c>
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d85,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d86,%edi
mov    $0xf,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x5,%edi
call   1030 <mdelay@plt>
mov    $0x3d0e,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,%r14d
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d85,%edi
mov    $0x10,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d86,%edi
mov    $0x1f,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x5,%edi
call   1030 <mdelay@plt>
mov    $0x3d01,%ebp
mov    $0x3d00,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <ov5648_rio4g_my_otp_read@plt>
xor    %ebp,%ebp
or     %ebx,%eax
setne  %bpl
add    %ebp,%ebp
jmp    12cb <ov5648_rio4g_check_otp+0x19b>
mov    $0x2,%ebp
mov    $0x3d00,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d01,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d02,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d03,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d04,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d05,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d06,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d07,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d08,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d09,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d0a,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d0b,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d0c,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d0d,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d0e,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
mov    $0x3d0f,%edi
xor    %esi,%esi
call   1040 <ov5648_rio4g_my_otp_write@plt>
test   $0x80,%r14b
mov    $0x1,%eax
cmove  %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ov5648_rio4g_check_otp(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = call i32 @ov5648_rio4g_my_otp_write(i32 15748, i32 192)
%12 = call i32 @ov5648_rio4g_my_otp_write(i32 15749, i32 0)
%13 = call i32 @ov5648_rio4g_my_otp_write(i32 15750, i32 15)
%14 = call i32 @ov5648_rio4g_my_otp_write(i32 15745, i32 1)
%15 = call i32 @mdelay(i32 5)
%16 = call i32 @ov5648_rio4g_my_otp_read(i32 15621)
store i32 %16, i32* %4
%17 = call i32 @ov5648_rio4g_my_otp_read(i32 15623)
store i32 %17, i32* %6
%18 = call i32 @ov5648_rio4g_my_otp_read(i32 15624)
store i32 %18, i32* %7
br label %50
19: ; preds = %1
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %36
22: ; preds = %19
%23 = call i32 @ov5648_rio4g_my_otp_write(i32 15748, i32 192)
%24 = call i32 @ov5648_rio4g_my_otp_write(i32 15749, i32 0)
%25 = call i32 @ov5648_rio4g_my_otp_write(i32 15750, i32 15)
%26 = call i32 @ov5648_rio4g_my_otp_write(i32 15745, i32 1)
%27 = call i32 @mdelay(i32 5)
%28 = call i32 @ov5648_rio4g_my_otp_read(i32 15630)
store i32 %28, i32* %4
%29 = call i32 @ov5648_rio4g_my_otp_write(i32 15748, i32 192)
%30 = call i32 @ov5648_rio4g_my_otp_write(i32 15749, i32 16)
%31 = call i32 @ov5648_rio4g_my_otp_write(i32 15750, i32 31)
%32 = call i32 @ov5648_rio4g_my_otp_write(i32 15745, i32 1)
%33 = call i32 @mdelay(i32 5)
%34 = call i32 @ov5648_rio4g_my_otp_read(i32 15616)
store i32 %34, i32* %6
%35 = call i32 @ov5648_rio4g_my_otp_read(i32 15617)
store i32 %35, i32* %7
br label %49
36: ; preds = %19
%37 = load i32, i32* %3
%38 = icmp eq i32 %37, 3
br i1 %38, label %39, label %48
39: ; preds = %36
%40 = call i32 @ov5648_rio4g_my_otp_write(i32 15748, i32 192)
%41 = call i32 @ov5648_rio4g_my_otp_write(i32 15749, i32 16)
%42 = call i32 @ov5648_rio4g_my_otp_write(i32 15750, i32 31)
%43 = call i32 @ov5648_rio4g_my_otp_write(i32 15745, i32 1)
%44 = call i32 @mdelay(i32 5)
%45 = call i32 @ov5648_rio4g_my_otp_read(i32 15623)
store i32 %45, i32* %4
%46 = call i32 @ov5648_rio4g_my_otp_read(i32 15625)
store i32 %46, i32* %6
%47 = call i32 @ov5648_rio4g_my_otp_read(i32 15626)
store i32 %47, i32* %7
br label %48
48: ; preds = %39, %36
br label %49
49: ; preds = %48, %22
br label %50
50: ; preds = %49, %10
%51 = load i32, i32* %4
%52 = and i32 %51, 128
store i32 %52, i32* %4
store i32 0, i32* %5
br label %53
53: ; preds = %60, %50
%54 = load i32, i32* %5
%55 = icmp slt i32 %54, 16
br i1 %55, label %56, label %63
56: ; preds = %53
%57 = load i32, i32* %5
%58 = add nsw i32 15616, %57
%59 = call i32 @ov5648_rio4g_my_otp_write(i32 %58, i32 0)
br label %60
60: ; preds = %56
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %53
63: ; preds = %53
%64 = load i32, i32* %4
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %63
store i32 1, i32* %2
br label %75
67: ; preds = %63
%68 = load i32, i32* %6
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load i32, i32* %7
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %70
store i32 0, i32* %2
br label %75
74: ; preds = %70, %67
store i32 2, i32* %2
br label %75
75: ; preds = %74, %73, %66
%76 = load i32, i32* %2
ret i32 %76
}

LLVM IR (-O2):
define i32 @ov5648_rio4g_check_otp(i32 %0) {
switch i32 %0, label %38 [
i32 1, label %2
i32 2, label %9
i32 3, label %21
]
2: ; preds = %1
%3 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15748, i32 192)
%4 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15749, i32 0)
%5 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15750, i32 15)
%6 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15745, i32 1)
%7 = tail call i32 @mdelay(i32 5)
%8 = tail call i32 @ov5648_rio4g_my_otp_read(i32 15621)
br label %28
9: ; preds = %1
%10 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15748, i32 192)
%11 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15749, i32 0)
%12 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15750, i32 15)
%13 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15745, i32 1)
%14 = tail call i32 @mdelay(i32 5)
%15 = tail call i32 @ov5648_rio4g_my_otp_read(i32 15630)
%16 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15748, i32 192)
%17 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15749, i32 16)
%18 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15750, i32 31)
%19 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15745, i32 1)
%20 = tail call i32 @mdelay(i32 5)
br label %28
21: ; preds = %1
%22 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15748, i32 192)
%23 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15749, i32 16)
%24 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15750, i32 31)
%25 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15745, i32 1)
%26 = tail call i32 @mdelay(i32 5)
%27 = tail call i32 @ov5648_rio4g_my_otp_read(i32 15623)
br label %28
28: ; preds = %2, %21, %9
%29 = phi i32 [ 15616, %9 ], [ 15625, %21 ], [ 15623, %2 ]
%30 = phi i32 [ 15617, %9 ], [ 15626, %21 ], [ 15624, %2 ]
%31 = phi i32 [ %15, %9 ], [ %27, %21 ], [ %8, %2 ]
%32 = tail call i32 @ov5648_rio4g_my_otp_read(i32 %29)
%33 = tail call i32 @ov5648_rio4g_my_otp_read(i32 %30)
%34 = icmp eq i32 %32, 0
%35 = icmp eq i32 %33, 0
%36 = select i1 %34, i1 %35, i1 false
%37 = select i1 %36, i32 0, i32 2
br label %38
38: ; preds = %28, %1
%39 = phi i32 [ undef, %1 ], [ %31, %28 ]
%40 = phi i32 [ 2, %1 ], [ %37, %28 ]
%41 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15616, i32 0)
%42 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15617, i32 0)
%43 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15618, i32 0)
%44 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15619, i32 0)
%45 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15620, i32 0)
%46 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15621, i32 0)
%47 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15622, i32 0)
%48 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15623, i32 0)
%49 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15624, i32 0)
%50 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15625, i32 0)
%51 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15626, i32 0)
%52 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15627, i32 0)
%53 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15628, i32 0)
%54 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15629, i32 0)
%55 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15630, i32 0)
%56 = tail call i32 @ov5648_rio4g_my_otp_write(i32 15631, i32 0)
%57 = and i32 %39, 128
%58 = icmp eq i32 %57, 0
%59 = select i1 %58, i32 %40, i32 1
ret i32 %59
}