#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 /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct cc_usb {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ao_printf(int, char *, ...);
int /*<<< orphan*/ cc_usb_printf(struct cc_usb *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ cc_usb_sync(struct cc_usb *);
void ao_self_block_write(struct cc_usb *cc, uint32_t address,
                         uint8_t block[256]) {
  int byte;
  cc_usb_sync(cc);
  cc_usb_printf(cc, "W %x\n", address);
  ao_printf(2, "write %08x\n", address);
  for (byte = 0; byte < 0x100; byte++) {
    ao_printf(2, " %02x", block[byte]);
    if ((byte & 0xf) == 0xf)
      ao_printf(2, "\n");
  }
  for (byte = 0; byte < 0x100; byte++) {
    cc_usb_printf(cc, "%c", block[byte]);
  }
}


x86 assembly (clang, -O0):
<ao_self_block_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <cc_usb_sync@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xea6(%rip),%rsi
call   1050 <cc_usb_printf@plt>
mov    -0xc(%rbp),%edx
mov    $0x2,%edi
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1040 <ao_printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    11dc <ao_self_block_write+0xac>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    $0x2,%edi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1040 <ao_printf@plt>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
cmp    $0xf,%eax
jne    11c9 <ao_self_block_write+0x99>
mov    $0x2,%edi
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1040 <ao_printf@plt>
jmp    11ce <ao_self_block_write+0x9e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117c <ao_self_block_write+0x4c>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    1219 <ao_self_block_write+0xe9>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe12(%rip),%rsi
call   1050 <cc_usb_printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e3 <ao_self_block_write+0xb3>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ao_self_block_write>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1030 <cc_usb_sync@plt>
lea    0xeb4(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1050 <cc_usb_printf@plt>
lea    0xea9(%rip),%rsi
mov    $0x2,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <ao_printf@plt>
lea    0xea0(%rip),%r15
lea    0xe8b(%rip),%r12
xor    %ebp,%ebp
jmp    118d <ao_self_block_write+0x5d>
nopl   (%rax)
add    $0x1,%rbp
cmp    $0x100,%rbp
je     11b8 <ao_self_block_write+0x88>
mov    (%rbx,%rbp,4),%edx
mov    $0x2,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <ao_printf@plt>
mov    %ebp,%eax
not    %eax
test   $0xf,%al
jne    1180 <ao_self_block_write+0x50>
mov    $0x2,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <ao_printf@plt>
jmp    1180 <ao_self_block_write+0x50>
xor    %ebp,%ebp
lea    0xe57(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%rbp,4),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <cc_usb_printf@plt>
add    $0x1,%rbp
cmp    $0x100,%rbp
jne    11d0 <ao_self_block_write+0xa0>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.cc_usb = type { i32 }
@.str = [6 x i8] c"W %x\0A\00"
@.str.1 = [12 x i8] c"write %08x\0A\00"
@.str.2 = [6 x i8] c" %02x\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [3 x i8] c"%c\00"
define void @ao_self_block_write(%struct.cc_usb* %0, i32 %1, i32* %2) {
%4 = alloca %struct.cc_usb*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store %struct.cc_usb* %0, %struct.cc_usb** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load %struct.cc_usb*, %struct.cc_usb** %4
%9 = call i32 @cc_usb_sync(%struct.cc_usb* %8)
%10 = load %struct.cc_usb*, %struct.cc_usb** %4
%11 = load i32, i32* %5
%12 = call i32 @cc_usb_printf(%struct.cc_usb* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %5
%14 = call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 0, i32* %7
br label %15
15: ; preds = %31, %3
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 256
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = load i32*, i32** %6
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %7
%26 = and i32 %25, 15
%27 = icmp eq i32 %26, 15
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %18
br label %31
31: ; preds = %30
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %15
34: ; preds = %15
store i32 0, i32* %7
br label %35
35: ; preds = %46, %34
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 256
br i1 %37, label %38, label %49
38: ; preds = %35
%39 = load %struct.cc_usb*, %struct.cc_usb** %4
%40 = load i32*, i32** %6
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = call i32 @cc_usb_printf(%struct.cc_usb* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %38
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %35
49: ; preds = %35
ret void
}

LLVM IR (-O2):
%struct.cc_usb = type { i32 }
@.str = [6 x i8] c"W %x\0A\00"
@.str.1 = [12 x i8] c"write %08x\0A\00"
@.str.2 = [6 x i8] c" %02x\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [3 x i8] c"%c\00"
define void @ao_self_block_write(%struct.cc_usb* %0, i32 %1, i32* nocapture %2) {
%4 = tail call i32 @cc_usb_sync(%struct.cc_usb* %0)
%5 = tail call i32 @cc_usb_printf(%struct.cc_usb* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = tail call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %7
7: ; preds = %3, %16
%8 = phi i64 [ 0, %3 ], [ %17, %16 ]
%9 = getelementptr inbounds i32, i32* %2, i64 %8
%10 = load i32, i32* %9
%11 = tail call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = and i64 %8, 15
%13 = icmp eq i64 %12, 15
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = tail call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %7, %14
%17 = add nuw nsw i64 %8, 1
%18 = icmp eq i64 %17, 256
br i1 %18, label %19, label %7
19: ; preds = %16, %19
%20 = phi i64 [ %24, %19 ], [ 0, %16 ]
%21 = getelementptr inbounds i32, i32* %2, i64 %20
%22 = load i32, i32* %21
%23 = tail call i32 @cc_usb_printf(%struct.cc_usb* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = add nuw nsw i64 %20, 1
%25 = icmp eq i64 %24, 256
br i1 %25, label %26, label %19
26: ; preds = %19
ret void
}