#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ PN5180_transceiveCommand(int *, int, int *, int);
int /*<<< orphan*/ UART1_Write_Text(char *);
bool PN5180A_readEEprom(uint8_t addr, uint8_t *buffer, uint8_t len) {
  uint8_t cmd[3];
  cmd[0] = (0x07);
  cmd[1] = addr;
  cmd[2] = len;
  if ((addr > 254) || ((addr + len) > 254)) {
    return false;
  }
  UART1_Write_Text("Reading EEPROM\r\n");
  PN5180_transceiveCommand(cmd, 3, buffer, len);
  return true;
}


x86 assembly (clang, -O0):
<PN5180A_readEEprom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x7,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xfe,-0x8(%rbp)
jg     1163 <PN5180A_readEEprom+0x43>
mov    -0x8(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    $0xfe,%eax
jle    116f <PN5180A_readEEprom+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1197 <PN5180A_readEEprom+0x77>
lea    0xe8a(%rip),%rdi
call   1040 <UART1_Write_Text@plt>
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x3,%esi
call   1030 <PN5180_transceiveCommand@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PN5180A_readEEprom>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x7,0xc(%rsp)
mov    %edi,0x10(%rsp)
mov    %edx,0x14(%rsp)
xor    %eax,%eax
cmp    $0xfe,%edi
jg     1175 <PN5180A_readEEprom+0x55>
mov    %edx,%ebx
add    %edx,%edi
cmp    $0xfe,%edi
jg     1175 <PN5180A_readEEprom+0x55>
mov    %rsi,%r14
lea    0xea9(%rip),%rdi
call   1040 <UART1_Write_Text@plt>
lea    0xc(%rsp),%rdi
mov    $0x3,%esi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1030 <PN5180_transceiveCommand@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Reading EEPROM\0D\0A\00"
define i32 @PN5180A_readEEprom(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [3 x i32]
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
store i32 7, i32* %9
%10 = load i32, i32* %5
%11 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 1
store i32 %10, i32* %11
%12 = load i32, i32* %7
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 2
store i32 %12, i32* %13
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 254
br i1 %15, label %21, label %16
16: ; preds = %3
%17 = load i32, i32* %5
%18 = load i32, i32* %7
%19 = add nsw i32 %17, %18
%20 = icmp sgt i32 %19, 254
br i1 %20, label %21, label %22
21: ; preds = %16, %3
store i32 0, i32* %4
br label %28
22: ; preds = %16
%23 = call i32 @UART1_Write_Text(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%24 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = load i32, i32* %7
%27 = call i32 @PN5180_transceiveCommand(i32* %24, i32 3, i32* %25, i32 %26)
store i32 1, i32* %4
br label %28
28: ; preds = %22, %21
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@.str = [17 x i8] c"Reading EEPROM\0D\0A\00"
define i32 @PN5180A_readEEprom(i32 %0, i32* %1, i32 %2) {
%4 = alloca [3 x i32]
%5 = bitcast [3 x i32]* %4 to i8*
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
store i32 7, i32* %6
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
store i32 %0, i32* %7
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
store i32 %2, i32* %8
%9 = icmp sgt i32 %0, 254
%10 = add nsw i32 %2, %0
%11 = icmp sgt i32 %10, 254
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = tail call i32 @UART1_Write_Text(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @PN5180_transceiveCommand(i32* %6, i32 3, i32* %1, i32 %2)
br label %16
16: ; preds = %3, %13
%17 = phi i32 [ 1, %13 ], [ 0, %3 ]
ret i32 %17
}