#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*/ assert(int /*<<< orphan*/);
int at24c_iic_read_(unsigned int, char *, unsigned int);
unsigned int at24c_iic_write_(unsigned int, char *, unsigned int);
unsigned at24c_read(unsigned addr, void *buf, unsigned nbyte) {
  char tmp[1u];
  unsigned cnt, dev;
  assert(buf != NULL);
  if (nbyte == 0)
    return 0;
  dev = (0xau << 3) | ((addr >> (1u * 8)) & 0x7);
  for (cnt = 0; cnt < 1u; ++cnt) {
    tmp[cnt] = (char)(addr >> (cnt * 8));
  }
  int retry = 0;
  while (at24c_iic_write_(dev, tmp, 1u) != 1u) {
    if (retry++ > 10000)
      return 0;
  }
  return at24c_iic_read_(dev, (char *)buf, nbyte);
}


x86 assembly (clang, -O0):
<at24c_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
jne    116a <at24c_read+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    1206 <at24c_read+0xd6>
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
and    $0x7,%eax
or     $0x50,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jae    11ac <at24c_read+0x7c>
mov    -0x8(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x3,%ecx
shr    %cl,%eax
mov    %al,%cl
mov    -0x1c(%rbp),%eax
mov    %cl,-0x15(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <at24c_read+0x50>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1030 <at24c_iic_write_@plt>
cmp    $0x1,%eax
je     11f4 <at24c_read+0xc4>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x2710,%eax
jle    11ef <at24c_read+0xbf>
movl   $0x0,-0x4(%rbp)
jmp    1206 <at24c_read+0xd6>
jmp    11b3 <at24c_read+0x83>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <at24c_iic_read_@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<at24c_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebp
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1040 <assert@plt>
xor    %r12d,%r12d
test   %r14d,%r14d
je     11ab <at24c_read+0x7b>
mov    %ebp,%ebx
shr    $0x8,%ebx
and    $0x7,%ebx
or     $0x50,%ebx
mov    %bpl,0x7(%rsp)
mov    $0x2712,%ebp
lea    0x7(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   1030 <at24c_iic_write_@plt>
cmp    $0x1,%eax
je     119b <at24c_read+0x6b>
add    $0xffffffff,%ebp
jne    1180 <at24c_read+0x50>
jmp    11ab <at24c_read+0x7b>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <at24c_iic_read_@plt>
mov    %eax,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @at24c_read(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [1 x i8]
%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 i8*, i8** %6
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 0, i32* %4
br label %56
19: ; preds = %3
%20 = load i32, i32* %5
%21 = lshr i32 %20, 8
%22 = and i32 %21, 7
%23 = or i32 80, %22
store i32 %23, i32* %10
store i32 0, i32* %9
br label %24
24: ; preds = %36, %19
%25 = load i32, i32* %9
%26 = icmp ult i32 %25, 1
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = load i32, i32* %5
%29 = load i32, i32* %9
%30 = mul i32 %29, 8
%31 = lshr i32 %28, %30
%32 = trunc i32 %31 to i8
%33 = load i32, i32* %9
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 %34
store i8 %32, i8* %35
br label %36
36: ; preds = %27
%37 = load i32, i32* %9
%38 = add i32 %37, 1
store i32 %38, i32* %9
br label %24
39: ; preds = %24
store i32 0, i32* %11
br label %40
40: ; preds = %50, %39
%41 = load i32, i32* %10
%42 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%43 = call i32 @at24c_iic_write_(i32 %41, i8* %42, i32 1)
%44 = icmp ne i32 %43, 1
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 1
store i32 %47, i32* %11
%48 = icmp sgt i32 %46, 10000
br i1 %48, label %49, label %50
49: ; preds = %45
store i32 0, i32* %4
br label %56
50: ; preds = %45
br label %40
51: ; preds = %40
%52 = load i32, i32* %10
%53 = load i8*, i8** %6
%54 = load i32, i32* %7
%55 = call i32 @at24c_iic_read_(i32 %52, i8* %53, i32 %54)
store i32 %55, i32* %4
br label %56
56: ; preds = %51, %49, %18
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
define i32 @at24c_read(i32 %0, i8* %1, i32 %2) {
%4 = alloca [1 x i8]
%5 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%6 = icmp ne i8* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp eq i32 %2, 0
br i1 %9, label %24, label %10
10: ; preds = %3
%11 = lshr i32 %0, 8
%12 = and i32 %11, 7
%13 = or i32 %12, 80
%14 = trunc i32 %0 to i8
store i8 %14, i8* %5
br label %15
15: ; preds = %19, %10
%16 = phi i32 [ 0, %10 ], [ %20, %19 ]
%17 = call i32 @at24c_iic_write_(i32 %13, i8* %5, i32 1)
%18 = icmp eq i32 %17, 1
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = add nuw nsw i32 %16, 1
%21 = icmp eq i32 %20, 10002
br i1 %21, label %24, label %15
22: ; preds = %15
%23 = call i32 @at24c_iic_read_(i32 %13, i8* %1, i32 %2)
br label %24
24: ; preds = %19, %22, %3
%25 = phi i32 [ 0, %3 ], [ %23, %22 ], [ 0, %19 ]
ret i32 %25
}