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


x86 assembly (clang, -O0):
<page_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
and    $0x7,%eax
or     $0x50,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jae    1164 <page_write+0x54>
mov    -0x8(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0x3,%ecx
shr    %cl,%eax
mov    %al,%cl
mov    -0x18(%rbp),%eax
mov    %cl,-0x25(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1138 <page_write+0x28>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    119d <page_write+0x8d>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%eax
mov    %cl,-0x25(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116d <page_write+0x5d>
movl   $0x0,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <at24c_iic_write_@plt>
mov    %eax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x2710,%eax
jle    11d8 <page_write+0xc8>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <page_write+0xe0>
jmp    11dd <page_write+0xcd>
cmpl   $0x1,-0x18(%rbp)
jb     11a4 <page_write+0x94>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<page_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    %bl,0xf(%rsp)
shr    $0x8,%ebx
and    $0x7,%ebx
lea    0x1(%rdx),%r15d
cmp    $0x2,%r15d
jb     1151 <page_write+0x31>
lea    0x10(%rsp),%rdi
add    $0xffffffff,%edx
add    $0x1,%rdx
call   1040 <memcpy@plt>
or     $0x50,%ebx
mov    $0x2712,%ebp
lea    0xf(%rsp),%r14
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <at24c_iic_write_@plt>
add    $0xffffffff,%ebp
je     117b <page_write+0x5b>
test   %eax,%eax
je     1160 <page_write+0x40>
add    $0xffffffff,%eax
jmp    117d <page_write+0x5d>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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