#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 read_buffer_otp(unsigned int addree, unsigned char *buff,
                    unsigned int len) {
  int i;
  unsigned int data, addr;
  addr = addree & 0xfffffffc;
  for (i = 0; i < len; i = i + 3) {
    if (one_read_time(addr, &data) < 0) {
      return -1;
    }
    buff[i] = ((data & 0xff000000) >> 24);
    buff[i + 1] = ((data & 0x00ff0000) >> 16);
    buff[i + 2] = ((data & 0x0000ff00) >> 8);
    addr = addr + 4;
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_buffer_otp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    11c9 <read_buffer_otp+0xb9>
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <one_read_time@plt>
cmp    $0x0,%rax
jge    1160 <read_buffer_otp+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <read_buffer_otp+0xc0>
mov    -0x1c(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x18(%rbp)
jmp    1132 <read_buffer_otp+0x22>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_buffer_otp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %edx,%edx
je     1179 <read_buffer_otp+0x69>
mov    %rsi,%r12
mov    %edi,%ebp
and    $0xfffffffc,%ebp
mov    %edx,%r15d
xor    %ebx,%ebx
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <one_read_time@plt>
test   %rax,%rax
js     117d <read_buffer_otp+0x6d>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
shr    $0x18,%ecx
mov    %r12,%rdx
mov    %cl,(%r12,%rbx,1)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x1(%r12,%rbx,1)
mov    %ah,0x2(%rdx,%rbx,1)
add    $0x4,%ebp
add    $0x3,%rbx
cmp    %r15,%rbx
jb     1140 <read_buffer_otp+0x30>
xor    %eax,%eax
jmp    1182 <read_buffer_otp+0x72>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_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
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i32, i32* %5
%12 = and i32 %11, -4
store i32 %12, i32* %10
store i32 0, i32* %8
br label %13
13: ; preds = %51, %3
%14 = load i32, i32* %8
%15 = load i32, i32* %7
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %54
17: ; preds = %13
%18 = load i32, i32* %10
%19 = call i64 @one_read_time(i32 %18, i32* %9)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %4
br label %55
22: ; preds = %17
%23 = load i32, i32* %9
%24 = and i32 %23, -16777216
%25 = lshr i32 %24, 24
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %6
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
%31 = load i32, i32* %9
%32 = and i32 %31, 16711680
%33 = lshr i32 %32, 16
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %6
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 %34, i8* %39
%40 = load i32, i32* %9
%41 = and i32 %40, 65280
%42 = lshr i32 %41, 8
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %6
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8 %43, i8* %48
%49 = load i32, i32* %10
%50 = add i32 %49, 4
store i32 %50, i32* %10
br label %51
51: ; preds = %22
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 3
store i32 %53, i32* %8
br label %13
54: ; preds = %13
store i32 0, i32* %4
br label %55
55: ; preds = %54, %21
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
define i32 @read_buffer_otp(i32 %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp eq i32 %2, 0
br i1 %6, label %31, label %7
7: ; preds = %3
%8 = and i32 %0, -4
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %7, %15
%11 = phi i64 [ 0, %7 ], [ %29, %15 ]
%12 = phi i32 [ %8, %7 ], [ %28, %15 ]
%13 = call i64 @one_read_time(i32 %12, i32* %4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %31, label %15
15: ; preds = %10
%16 = load i32, i32* %4
%17 = lshr i32 %16, 24
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds i8, i8* %1, i64 %11
store i8 %18, i8* %19
%20 = lshr i32 %16, 16
%21 = trunc i32 %20 to i8
%22 = add nuw nsw i64 %11, 1
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 %21, i8* %23
%24 = lshr i32 %16, 8
%25 = trunc i32 %24 to i8
%26 = add nuw nsw i64 %11, 2
%27 = getelementptr inbounds i8, i8* %1, i64 %26
store i8 %25, i8* %27
%28 = add i32 %12, 4
%29 = add nuw i64 %11, 3
%30 = icmp ult i64 %29, %9
br i1 %30, label %10, label %31
31: ; preds = %10, %15, %3
%32 = phi i32 [ 0, %3 ], [ 0, %15 ], [ -1, %10 ]
ret i32 %32
}