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

/* Variables and functions */
int /*<<< orphan*/ c2_pulse();
int /*<<< orphan*/ c2_recv(int);
int /*<<< orphan*/ c2_send(int, int);
int /*<<< orphan*/ gpio_input(int, int);
int /*<<< orphan*/ gpio_output(int, int);
void c2_data_write(uint32_t data, int bytes) {
  c2_pulse();
  gpio_output(4, 13);
  c2_send(1, 2);
  c2_send(bytes - 1, 2);
  c2_send(data, 8 * bytes);
  gpio_input(4, 13);
  c2_pulse();
  while (!c2_recv(1))
    ;
}


x86 assembly (clang, -O0):
<c2_data_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <c2_pulse@plt>
mov    $0x4,%edi
mov    $0xd,%esi
call   1060 <gpio_output@plt>
mov    $0x1,%edi
mov    $0x2,%esi
call   1070 <c2_send@plt>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    $0x2,%esi
call   1070 <c2_send@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
shl    $0x3,%esi
call   1070 <c2_send@plt>
mov    $0x4,%edi
mov    $0xd,%esi
call   1040 <gpio_input@plt>
mov    $0x0,%al
call   1030 <c2_pulse@plt>
mov    $0x1,%edi
call   1050 <c2_recv@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d6 <c2_data_write+0x86>
jmp    11db <c2_data_write+0x8b>
jmp    11b7 <c2_data_write+0x67>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c2_data_write>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <c2_pulse@plt>
mov    $0x4,%edi
mov    $0xd,%esi
call   1060 <gpio_output@plt>
mov    $0x1,%edi
mov    $0x2,%esi
call   1070 <c2_send@plt>
lea    -0x1(%rbx),%edi
mov    $0x2,%esi
call   1070 <c2_send@plt>
shl    $0x3,%ebx
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <c2_send@plt>
mov    $0x4,%edi
mov    $0xd,%esi
call   1040 <gpio_input@plt>
xor    %eax,%eax
call   1030 <c2_pulse@plt>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1050 <c2_recv@plt>
test   %eax,%eax
je     11b0 <c2_data_write+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @c2_data_write(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = call i32 (...) @c2_pulse()
%6 = call i32 @gpio_output(i32 4, i32 13)
%7 = call i32 @c2_send(i32 1, i32 2)
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = call i32 @c2_send(i32 %9, i32 2)
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = mul nsw i32 8, %12
%14 = call i32 @c2_send(i32 %11, i32 %13)
%15 = call i32 @gpio_input(i32 4, i32 13)
%16 = call i32 (...) @c2_pulse()
br label %17
17: ; preds = %21, %2
%18 = call i32 @c2_recv(i32 1)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %22
21: ; preds = %17
br label %17
22: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @c2_data_write(i32 %0, i32 %1) {
%3 = tail call i32 (...) @c2_pulse()
%4 = tail call i32 @gpio_output(i32 4, i32 13)
%5 = tail call i32 @c2_send(i32 1, i32 2)
%6 = add nsw i32 %1, -1
%7 = tail call i32 @c2_send(i32 %6, i32 2)
%8 = shl nsw i32 %1, 3
%9 = tail call i32 @c2_send(i32 %0, i32 %8)
%10 = tail call i32 @gpio_input(i32 4, i32 13)
%11 = tail call i32 (...) @c2_pulse()
br label %12
12: ; preds = %12, %2
%13 = tail call i32 @c2_recv(i32 1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %12, label %15
15: ; preds = %12
ret void
}