#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;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stdout;
void print_data(uint8_t *buf, uint32_t bytes_read) {
  static uint8_t remaining_bytes = 0;
  for (int i = 0; i < bytes_read; i++) {
    if (remaining_bytes == 0) {
      remaining_bytes = buf[i];
    } else {
      remaining_bytes -= 1;
      putchar(buf[i]);
    }
  }
  fflush(stdout);
}


x86 assembly (clang, -O0):
<print_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1197 <print_data+0x77>
cmpl   $0x0,0x2eeb(%rip)
jne    1165 <print_data+0x45>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,0x2ed4(%rip)
jmp    1184 <print_data+0x64>
mov    0x2ec9(%rip),%eax
sub    $0x1,%eax
mov    %eax,0x2ec0(%rip)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <putchar@plt>
jmp    1189 <print_data+0x69>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <print_data+0x16>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_data>:
push   %r15
push   %r14
push   %rbx
test   %esi,%esi
jle    1171 <print_data+0x51>
mov    %rdi,%r14
mov    %esi,%r15d
mov    0x2eff(%rip),%eax
xor    %ebx,%ebx
jmp    1161 <print_data+0x41>
nopl   0x0(%rax)
add    $0xffffffff,%eax
mov    %eax,0x2eeb(%rip)
mov    (%r14,%rbx,4),%edi
call   1030 <putchar@plt>
mov    0x2edc(%rip),%eax
add    $0x1,%rbx
cmp    %rbx,%r15
je     1171 <print_data+0x51>
test   %eax,%eax
jne    1140 <print_data+0x20>
mov    (%r14,%rbx,4),%eax
mov    %eax,0x2ec5(%rip)
jmp    1158 <print_data+0x38>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fflush@plt>

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

LLVM IR (-O2):
@print_data.remaining_bytes = internal unnamed_addr global i32 0
@stdout = global i32 0
define void @print_data(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = load i32, i32* @print_data.remaining_bytes
br label %10
7: ; preds = %23, %2
%8 = load i32, i32* @stdout
%9 = tail call i32 @fflush(i32 %8)
ret void
10: ; preds = %4, %23
%11 = phi i32 [ %6, %4 ], [ %24, %23 ]
%12 = phi i64 [ 0, %4 ], [ %25, %23 ]
%13 = icmp eq i32 %11, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = getelementptr inbounds i32, i32* %0, i64 %12
%16 = load i32, i32* %15
store i32 %16, i32* @print_data.remaining_bytes
br label %23
17: ; preds = %10
%18 = add nsw i32 %11, -1
store i32 %18, i32* @print_data.remaining_bytes
%19 = getelementptr inbounds i32, i32* %0, i64 %12
%20 = load i32, i32* %19
%21 = tail call i32 @putchar(i32 %20)
%22 = load i32, i32* @print_data.remaining_bytes
br label %23
23: ; preds = %14, %17
%24 = phi i32 [ %16, %14 ], [ %22, %17 ]
%25 = add nuw nsw i64 %12, 1
%26 = icmp eq i64 %25, %5
br i1 %26, label %7, label %10
}