int check_otp_VCM(int index, int code, struct msm_sensor_ctrl_t *a_ctrl) {
  int flag, bank;
  int address;
  bank = 0xc0 + 16;
  write_sccb16(0x3d84, bank, a_ctrl);
  write_sccb16(0x3d81, 0x01, a_ctrl);
  msleep(5);
  address = 0x3d00 + (index - 1) * 4 + code * 2;
  flag = read_sccb16(address, a_ctrl);
  pr_err("otpVCM %s index =%d , code=%d ,flag=0x%x", __func__, index, code,
         flag);
  flag = flag & 0xc0;
  write_sccb16(0x3d81, 0x00, a_ctrl);
  clear_otp_buffer(a_ctrl);
  if (flag == 0) {
    return 0;
  } else if (flag & 0x80) {
    return 1;
  } else {
    return 2;
  }
}


x86 assembly (clang, -O0):
<check_otp_VCM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xd0,-0x20(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    $0x3d84,%edi
mov    $0x0,%al
call   1070 <write_sccb16@plt>
mov    -0x18(%rbp),%rdx
mov    $0x3d81,%edi
mov    $0x1,%esi
mov    $0x0,%al
call   1070 <write_sccb16@plt>
mov    $0x5,%edi
mov    $0x0,%al
call   1040 <msleep@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
shl    $0x2,%eax
add    $0x3d00,%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1030 <read_sccb16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe28(%rip),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1060 <pr_err@plt>
mov    -0x1c(%rbp),%eax
and    $0xc0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdx
mov    $0x3d81,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1070 <write_sccb16@plt>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1050 <clear_otp_buffer@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1224 <check_otp_VCM+0xd4>
movl   $0x0,-0x4(%rbp)
jmp    1248 <check_otp_VCM+0xf8>
mov    -0x1c(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1241 <check_otp_VCM+0xf1>
movl   $0x1,-0x4(%rbp)
jmp    1248 <check_otp_VCM+0xf8>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_otp_VCM>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %esi,%r14d
mov    %edi,%r15d
mov    $0x3d84,%edi
mov    $0xd0,%esi
xor    %eax,%eax
call   1070 <write_sccb16@plt>
mov    $0x1,%r13d
mov    $0x3d81,%edi
mov    $0x1,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <write_sccb16@plt>
mov    $0x5,%edi
xor    %eax,%eax
call   1040 <msleep@plt>
lea    (%r14,%r14,1),%eax
lea    (%rax,%r15,4),%edi
add    $0x3cfc,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <read_sccb16@plt>
mov    %eax,%ebx
lea    0xe44(%rip),%rdi
lea    0xe66(%rip),%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <pr_err@plt>
mov    %ebx,%ebp
and    $0xc0,%ebp
mov    $0x3d81,%edi
xor    %esi,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <write_sccb16@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <clear_otp_buffer@plt>
and    $0x80,%ebx
cmp    $0x1,%ebx
adc    $0x0,%r13d
test   %ebp,%ebp
cmove  %ebp,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.msm_sensor_ctrl_t = type opaque
@.str = [41 x i8] c"otpVCM %s index =%d , code=%d ,flag=0x%x\00"
@__func__.check_otp_VCM = [14 x i8] c"check_otp_VCM\00"
define i32 @check_otp_VCM(i32 %0, i32 %1, %struct.msm_sensor_ctrl_t* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.msm_sensor_ctrl_t*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store %struct.msm_sensor_ctrl_t* %2, %struct.msm_sensor_ctrl_t** %7
store i32 208, i32* %9
%11 = load i32, i32* %9
%12 = load %struct.msm_sensor_ctrl_t*, %struct.msm_sensor_ctrl_t** %7
%13 = call i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...) bitcast (i32 (...)* @write_sccb16 to i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...)*)(i32 15748, i32 %11, %struct.msm_sensor_ctrl_t* %12)
%14 = load %struct.msm_sensor_ctrl_t*, %struct.msm_sensor_ctrl_t** %7
%15 = call i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...) bitcast (i32 (...)* @write_sccb16 to i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...)*)(i32 15745, i32 1, %struct.msm_sensor_ctrl_t* %14)
%16 = call i32 (i32, ...) bitcast (i32 (...)* @msleep to i32 (i32, ...)*)(i32 5)
%17 = load i32, i32* %5
%18 = sub nsw i32 %17, 1
%19 = mul nsw i32 %18, 4
%20 = add nsw i32 15616, %19
%21 = load i32, i32* %6
%22 = mul nsw i32 %21, 2
%23 = add nsw i32 %20, %22
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = load %struct.msm_sensor_ctrl_t*, %struct.msm_sensor_ctrl_t** %7
%26 = call i32 (i32, %struct.msm_sensor_ctrl_t*, ...) bitcast (i32 (...)* @read_sccb16 to i32 (i32, %struct.msm_sensor_ctrl_t*, ...)*)(i32 %24, %struct.msm_sensor_ctrl_t* %25)
store i32 %26, i32* %8
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = load i32, i32* %8
%30 = call i32 (i8*, i8*, i32, i32, i32, ...) bitcast (i32 (...)* @pr_err to i32 (i8*, i8*, i32, i32, i32, ...)*)(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__func__.check_otp_VCM, i64 0, i64 0), i32 %27, i32 %28, i32 %29)
%31 = load i32, i32* %8
%32 = and i32 %31, 192
store i32 %32, i32* %8
%33 = load %struct.msm_sensor_ctrl_t*, %struct.msm_sensor_ctrl_t** %7
%34 = call i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...) bitcast (i32 (...)* @write_sccb16 to i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...)*)(i32 15745, i32 0, %struct.msm_sensor_ctrl_t* %33)
%35 = load %struct.msm_sensor_ctrl_t*, %struct.msm_sensor_ctrl_t** %7
%36 = call i32 (%struct.msm_sensor_ctrl_t*, ...) bitcast (i32 (...)* @clear_otp_buffer to i32 (%struct.msm_sensor_ctrl_t*, ...)*)(%struct.msm_sensor_ctrl_t* %35)
%37 = load i32, i32* %8
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %3
store i32 0, i32* %4
br label %46
40: ; preds = %3
%41 = load i32, i32* %8
%42 = and i32 %41, 128
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 1, i32* %4
br label %46
45: ; preds = %40
store i32 2, i32* %4
br label %46
46: ; preds = %45, %44, %39
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
%struct.msm_sensor_ctrl_t = type opaque
@.str = [41 x i8] c"otpVCM %s index =%d , code=%d ,flag=0x%x\00"
@__func__.check_otp_VCM = [14 x i8] c"check_otp_VCM\00"
define i32 @check_otp_VCM(i32 %0, i32 %1, %struct.msm_sensor_ctrl_t* %2) {
%4 = tail call i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...) bitcast (i32 (...)* @write_sccb16 to i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...)*)(i32 15748, i32 208, %struct.msm_sensor_ctrl_t* %2)
%5 = tail call i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...) bitcast (i32 (...)* @write_sccb16 to i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...)*)(i32 15745, i32 1, %struct.msm_sensor_ctrl_t* %2)
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @msleep to i32 (i32, ...)*)(i32 5)
%7 = shl i32 %0, 2
%8 = add i32 %7, 15612
%9 = shl nsw i32 %1, 1
%10 = add nsw i32 %8, %9
%11 = tail call i32 (i32, %struct.msm_sensor_ctrl_t*, ...) bitcast (i32 (...)* @read_sccb16 to i32 (i32, %struct.msm_sensor_ctrl_t*, ...)*)(i32 %10, %struct.msm_sensor_ctrl_t* %2)
%12 = tail call i32 (i8*, i8*, i32, i32, i32, ...) bitcast (i32 (...)* @pr_err to i32 (i8*, i8*, i32, i32, i32, ...)*)(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__func__.check_otp_VCM, i64 0, i64 0), i32 %0, i32 %1, i32 %11)
%13 = and i32 %11, 192
%14 = tail call i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...) bitcast (i32 (...)* @write_sccb16 to i32 (i32, i32, %struct.msm_sensor_ctrl_t*, ...)*)(i32 15745, i32 0, %struct.msm_sensor_ctrl_t* %2)
%15 = tail call i32 (%struct.msm_sensor_ctrl_t*, ...) bitcast (i32 (...)* @clear_otp_buffer to i32 (%struct.msm_sensor_ctrl_t*, ...)*)(%struct.msm_sensor_ctrl_t* %2)
%16 = icmp eq i32 %13, 0
%17 = and i32 %11, 128
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i32 2, i32 1
%20 = select i1 %16, i32 0, i32 %19
ret i32 %20
}