#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 /*<<< orphan*/ ov5648_otp_write(int, int);
int ov5648ff_otp_read(int);
int ov5648ff_check_otp(int index) {
  int temp, i;
  int address;
  if (index < 2) {
    ov5648_otp_write(0x3d84, 0xc0);
    ov5648_otp_write(0x3d85, 0x00);
    ov5648_otp_write(0x3d86, 0x0f);
    ov5648_otp_write(0x3d81, 0x01);
    mdelay(1);
    address = 0x3d05 + index * 9;
  } else {
    ov5648_otp_write(0x3d84, 0xc0);
    ov5648_otp_write(0x3d85, 0x10);
    ov5648_otp_write(0x3d86, 0x1f);
    ov5648_otp_write(0x3d81, 0x01);
    mdelay(1);
    address = 0x3d05 + index * 9 - 16;
  }
  temp = ov5648ff_otp_read(address);
  ov5648_otp_write(0x3d81, 0x00);
  for (i = 0; i < 16; i++) {
    ov5648_otp_write(0x3d00 + i, 0x00);
  }
  if (!temp) {
    return 0;
  } else if ((!(temp & 0x80)) && (temp & 0x7f)) {
    return 2;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<ov5648ff_check_otp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1199 <ov5648ff_check_otp+0x69>
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d85,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d86,%edi
mov    $0xf,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x1,%edi
call   1030 <mdelay@plt>
imul   $0x9,-0x8(%rbp),%eax
add    $0x3d05,%eax
mov    %eax,-0x14(%rbp)
jmp    11ee <ov5648ff_check_otp+0xbe>
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d85,%edi
mov    $0x10,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d86,%edi
mov    $0x1f,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x1,%edi
call   1030 <mdelay@plt>
imul   $0x9,-0x8(%rbp),%eax
add    $0x3d05,%eax
sub    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <ov5648ff_otp_read@plt>
mov    %eax,-0xc(%rbp)
mov    $0x3d81,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x10,-0x10(%rbp)
jge    1234 <ov5648ff_check_otp+0x104>
mov    -0x10(%rbp),%edi
add    $0x3d00,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    120c <ov5648ff_check_otp+0xdc>
cmpl   $0x0,-0xc(%rbp)
jne    124a <ov5648ff_check_otp+0x11a>
movl   $0x0,-0x4(%rbp)
jmp    127d <ov5648ff_check_otp+0x14d>
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1276 <ov5648ff_check_otp+0x146>
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
cmp    $0x0,%eax
je     1276 <ov5648ff_check_otp+0x146>
movl   $0x2,-0x4(%rbp)
jmp    127d <ov5648ff_check_otp+0x14d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ov5648ff_check_otp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
xor    %ebx,%ebx
xor    %ebp,%ebp
cmp    $0x2,%edi
setl   %bl
setge  %bpl
mov    $0x3d84,%edi
mov    $0xc0,%esi
call   1040 <ov5648_otp_write@plt>
shl    $0x4,%ebp
lea    0xf(%rbp),%r15d
shl    $0x4,%ebx
mov    $0x3d85,%edi
mov    %ebp,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d86,%edi
mov    %r15d,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d81,%edi
mov    $0x1,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x1,%edi
call   1030 <mdelay@plt>
lea    (%r14,%r14,8),%eax
lea    (%rbx,%rax,1),%edi
add    $0x3cf5,%edi
call   1050 <ov5648ff_otp_read@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    $0x3d81,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d00,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d01,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d02,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d03,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d04,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d05,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d06,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d07,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d08,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d09,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d0a,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d0b,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d0c,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d0d,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d0e,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
mov    $0x3d0f,%edi
xor    %esi,%esi
call   1040 <ov5648_otp_write@plt>
test   %ebp,%ebp
je     1293 <ov5648ff_check_otp+0x163>
movzbl %bpl,%eax
mov    %eax,%ecx
shr    $0x7,%ecx
test   $0x7f,%al
sete   %al
or     %cl,%al
movzbl %al,%eax
mov    $0x2,%ebx
sub    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ov5648ff_check_otp(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = call i32 @ov5648_otp_write(i32 15748, i32 192)
%11 = call i32 @ov5648_otp_write(i32 15749, i32 0)
%12 = call i32 @ov5648_otp_write(i32 15750, i32 15)
%13 = call i32 @ov5648_otp_write(i32 15745, i32 1)
%14 = call i32 @mdelay(i32 1)
%15 = load i32, i32* %3
%16 = mul nsw i32 %15, 9
%17 = add nsw i32 15621, %16
store i32 %17, i32* %6
br label %28
18: ; preds = %1
%19 = call i32 @ov5648_otp_write(i32 15748, i32 192)
%20 = call i32 @ov5648_otp_write(i32 15749, i32 16)
%21 = call i32 @ov5648_otp_write(i32 15750, i32 31)
%22 = call i32 @ov5648_otp_write(i32 15745, i32 1)
%23 = call i32 @mdelay(i32 1)
%24 = load i32, i32* %3
%25 = mul nsw i32 %24, 9
%26 = add nsw i32 15621, %25
%27 = sub nsw i32 %26, 16
store i32 %27, i32* %6
br label %28
28: ; preds = %18, %9
%29 = load i32, i32* %6
%30 = call i32 @ov5648ff_otp_read(i32 %29)
store i32 %30, i32* %4
%31 = call i32 @ov5648_otp_write(i32 15745, i32 0)
store i32 0, i32* %5
br label %32
32: ; preds = %39, %28
%33 = load i32, i32* %5
%34 = icmp slt i32 %33, 16
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i32, i32* %5
%37 = add nsw i32 15616, %36
%38 = call i32 @ov5648_otp_write(i32 %37, i32 0)
br label %39
39: ; preds = %35
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %32
42: ; preds = %32
%43 = load i32, i32* %4
%44 = icmp ne i32 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %42
store i32 0, i32* %2
br label %56
46: ; preds = %42
%47 = load i32, i32* %4
%48 = and i32 %47, 128
%49 = icmp ne i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %46
%51 = load i32, i32* %4
%52 = and i32 %51, 127
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %50
store i32 2, i32* %2
br label %56
55: ; preds = %50, %46
store i32 1, i32* %2
br label %56
56: ; preds = %55, %54, %45
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
define i32 @ov5648ff_check_otp(i32 %0) {
%2 = icmp slt i32 %0, 2
%3 = tail call i32 @ov5648_otp_write(i32 15748, i32 192)
%4 = select i1 %2, i32 0, i32 16
%5 = select i1 %2, i32 15, i32 31
%6 = select i1 %2, i32 15621, i32 15605
%7 = tail call i32 @ov5648_otp_write(i32 15749, i32 %4)
%8 = tail call i32 @ov5648_otp_write(i32 15750, i32 %5)
%9 = tail call i32 @ov5648_otp_write(i32 15745, i32 1)
%10 = tail call i32 @mdelay(i32 1)
%11 = mul nsw i32 %0, 9
%12 = add nsw i32 %11, %6
%13 = tail call i32 @ov5648ff_otp_read(i32 %12)
%14 = tail call i32 @ov5648_otp_write(i32 15745, i32 0)
%15 = tail call i32 @ov5648_otp_write(i32 15616, i32 0)
%16 = tail call i32 @ov5648_otp_write(i32 15617, i32 0)
%17 = tail call i32 @ov5648_otp_write(i32 15618, i32 0)
%18 = tail call i32 @ov5648_otp_write(i32 15619, i32 0)
%19 = tail call i32 @ov5648_otp_write(i32 15620, i32 0)
%20 = tail call i32 @ov5648_otp_write(i32 15621, i32 0)
%21 = tail call i32 @ov5648_otp_write(i32 15622, i32 0)
%22 = tail call i32 @ov5648_otp_write(i32 15623, i32 0)
%23 = tail call i32 @ov5648_otp_write(i32 15624, i32 0)
%24 = tail call i32 @ov5648_otp_write(i32 15625, i32 0)
%25 = tail call i32 @ov5648_otp_write(i32 15626, i32 0)
%26 = tail call i32 @ov5648_otp_write(i32 15627, i32 0)
%27 = tail call i32 @ov5648_otp_write(i32 15628, i32 0)
%28 = tail call i32 @ov5648_otp_write(i32 15629, i32 0)
%29 = tail call i32 @ov5648_otp_write(i32 15630, i32 0)
%30 = tail call i32 @ov5648_otp_write(i32 15631, i32 0)
%31 = icmp eq i32 %13, 0
br i1 %31, label %39, label %32
32: ; preds = %1
%33 = and i32 %13, 128
%34 = icmp ne i32 %33, 0
%35 = and i32 %13, 127
%36 = icmp eq i32 %35, 0
%37 = or i1 %34, %36
%38 = select i1 %37, i32 1, i32 2
br label %39
39: ; preds = %32, %1
%40 = phi i32 [ 0, %1 ], [ %38, %32 ]
ret i32 %40
}