#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 */
scalar_t__ one_read_time(unsigned int, unsigned int *);
int /*<<< orphan*/ one_write_time(unsigned int, unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int);
int write_buffer_otp(unsigned int addree, unsigned char *buff,
                     unsigned int len) {
  int i;
  unsigned int data, addr, comp_data;
  addr = addree & 0xfffffffc;
  for (i = 0; i < len; i = i + 3) {
    data = ((buff[i] << 24) | (buff[i + 1] << 16) | (buff[i + 2] << 8) | 0);
    if (one_read_time(addr, &comp_data) < 0) {
      return -1;
    }
    if (comp_data != 0) {
      printf("otp Already write %x \n", comp_data);
      return -1;
    }
    one_write_time(addr, data);
    if (one_read_time(addr, &comp_data) < 0) {
      return -1;
    }
    addr = addr + 4;
  }
  return 0;
}


x86 assembly (clang, -O0):
<write_buffer_otp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    122a <write_buffer_otp+0xfa>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
shl    $0x18,%eax
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%edx
add    $0x2,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     $0x0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1050 <one_read_time@plt>
cmp    $0x0,%rax
jge    11c1 <write_buffer_otp+0x91>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <write_buffer_otp+0x101>
cmpl   $0x0,-0x24(%rbp)
je     11e6 <write_buffer_otp+0xb6>
mov    -0x24(%rbp),%esi
lea    0xe2b(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <write_buffer_otp+0x101>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <one_write_time@plt>
mov    -0x20(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1050 <one_read_time@plt>
cmp    $0x0,%rax
jge    1213 <write_buffer_otp+0xe3>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <write_buffer_otp+0x101>
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x18(%rbp)
jmp    1152 <write_buffer_otp+0x22>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_buffer_otp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
test   %edx,%edx
je     11c8 <write_buffer_otp+0x98>
mov    %edi,%ebp
and    $0xfffffffc,%ebp
mov    %edx,%eax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
mov    $0xffffffff,%r12d
mov    0x10(%rsp),%rax
movzbl (%rax,%r13,1),%r15d
movzbl 0x1(%rax,%r13,1),%r14d
movzbl 0x2(%rax,%r13,1),%ebx
mov    %ebp,%edi
lea    0x4(%rsp),%rsi
call   1050 <one_read_time@plt>
test   %rax,%rax
js     11d9 <write_buffer_otp+0xa9>
mov    0x4(%rsp),%esi
test   %esi,%esi
jne    11cd <write_buffer_otp+0x9d>
shl    $0x18,%r15d
shl    $0x10,%r14d
or     %r15d,%r14d
shl    $0x8,%ebx
or     %r14d,%ebx
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <one_write_time@plt>
mov    %ebp,%edi
lea    0x4(%rsp),%rsi
call   1050 <one_read_time@plt>
test   %rax,%rax
js     11d9 <write_buffer_otp+0xa9>
add    $0x4,%ebp
add    $0x3,%r13
cmp    0x8(%rsp),%r13
jb     1160 <write_buffer_otp+0x30>
xor    %r12d,%r12d
jmp    11d9 <write_buffer_otp+0xa9>
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"otp Already write %x \0A\00"
define i32 @write_buffer_otp(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i32, i32* %5
%13 = and i32 %12, -4
store i32 %13, i32* %10
store i32 0, i32* %8
br label %14
14: ; preds = %66, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %69
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = shl i32 %24, 24
%26 = load i8*, i8** %6
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = shl i32 %32, 16
%34 = or i32 %25, %33
%35 = load i8*, i8** %6
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = shl i32 %41, 8
%43 = or i32 %34, %42
%44 = or i32 %43, 0
store i32 %44, i32* %9
%45 = load i32, i32* %10
%46 = call i64 @one_read_time(i32 %45, i32* %11)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %18
store i32 -1, i32* %4
br label %70
49: ; preds = %18
%50 = load i32, i32* %11
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32, i32* %11
%54 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %53)
store i32 -1, i32* %4
br label %70
55: ; preds = %49
%56 = load i32, i32* %10
%57 = load i32, i32* %9
%58 = call i32 @one_write_time(i32 %56, i32 %57)
%59 = load i32, i32* %10
%60 = call i64 @one_read_time(i32 %59, i32* %11)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %55
store i32 -1, i32* %4
br label %70
63: ; preds = %55
%64 = load i32, i32* %10
%65 = add i32 %64, 4
store i32 %65, i32* %10
br label %66
66: ; preds = %63
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 3
store i32 %68, i32* %8
br label %14
69: ; preds = %14
store i32 0, i32* %4
br label %70
70: ; preds = %69, %62, %52, %48
%71 = load i32, i32* %4
ret i32 %71
}

LLVM IR (-O2):
@.str = [23 x i8] c"otp Already write %x \0A\00"
define i32 @write_buffer_otp(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp eq i32 %2, 0
br i1 %6, label %44, label %7
7: ; preds = %3
%8 = and i32 %0, -4
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %7, %40
%11 = phi i64 [ 0, %7 ], [ %42, %40 ]
%12 = phi i32 [ %8, %7 ], [ %41, %40 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %11
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = shl nuw i32 %15, 24
%17 = add nuw nsw i64 %11, 1
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = shl nuw nsw i32 %20, 16
%22 = or i32 %21, %16
%23 = add nuw nsw i64 %11, 2
%24 = getelementptr inbounds i8, i8* %1, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = shl nuw nsw i32 %26, 8
%28 = or i32 %22, %27
%29 = call i64 @one_read_time(i32 %12, i32* %4)
%30 = icmp slt i64 %29, 0
br i1 %30, label %44, label %31
31: ; preds = %10
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %44
36: ; preds = %31
%37 = call i32 @one_write_time(i32 %12, i32 %28)
%38 = call i64 @one_read_time(i32 %12, i32* %4)
%39 = icmp slt i64 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %36
%41 = add i32 %12, 4
%42 = add nuw i64 %11, 3
%43 = icmp ult i64 %42, %9
br i1 %43, label %10, label %44
44: ; preds = %10, %36, %40, %3, %34
%45 = phi i32 [ -1, %34 ], [ 0, %3 ], [ -1, %10 ], [ -1, %36 ], [ 0, %40 ]
ret i32 %45
}