#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*/ writeByte(int);
int /*<<< orphan*/ writeSyncFrame(int);
void writeBlock(unsigned int block, unsigned char *data, int sync) {
  int checksum = 0;
  writeSyncFrame(sync);
  writeByte(block);
  for (int i = 0; i < 128; i++) {
    char c = data[i];
    checksum += c;
    writeByte(c);
  }
  writeByte(checksum);
}


x86 assembly (clang, -O0):
<writeBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <writeSyncFrame@plt>
mov    -0x4(%rbp),%edi
call   1040 <writeByte@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x80,-0x1c(%rbp)
jge    118c <writeBlock+0x6c>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
movsbl -0x1d(%rbp),%edi
call   1040 <writeByte@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1150 <writeBlock+0x30>
mov    -0x18(%rbp),%edi
call   1040 <writeByte@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeBlock>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    %edx,%edi
call   1030 <writeSyncFrame@plt>
mov    %ebp,%edi
call   1040 <writeByte@plt>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
add    %edi,%ebp
call   1040 <writeByte@plt>
add    $0x1,%rbx
cmp    $0x80,%rbx
jne    1140 <writeBlock+0x20>
mov    %ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <writeByte@plt>

LLVM IR (-O0):
define void @writeBlock(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%10 = load i32, i32* %6
%11 = call i32 @writeSyncFrame(i32 %10)
%12 = load i32, i32* %4
%13 = call i32 @writeByte(i32 %12)
store i32 0, i32* %8
br label %14
14: ; preds = %30, %3
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 128
br i1 %16, label %17, label %33
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
store i8 %22, i8* %9
%23 = load i8, i8* %9
%24 = sext i8 %23 to i32
%25 = load i32, i32* %7
%26 = add nsw i32 %25, %24
store i32 %26, i32* %7
%27 = load i8, i8* %9
%28 = sext i8 %27 to i32
%29 = call i32 @writeByte(i32 %28)
br label %30
30: ; preds = %17
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %14
33: ; preds = %14
%34 = load i32, i32* %7
%35 = call i32 @writeByte(i32 %34)
ret void
}

LLVM IR (-O2):
define void @writeBlock(i32 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @writeSyncFrame(i32 %2)
%5 = tail call i32 @writeByte(i32 %0)
br label %8
6: ; preds = %8
%7 = tail call i32 @writeByte(i32 %14)
ret void
8: ; preds = %3, %8
%9 = phi i64 [ 0, %3 ], [ %16, %8 ]
%10 = phi i32 [ 0, %3 ], [ %14, %8 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %9
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = add nsw i32 %10, %13
%15 = tail call i32 @writeByte(i32 %13)
%16 = add nuw nsw i64 %9, 1
%17 = icmp eq i64 %16, 128
br i1 %17, label %6, label %8
}