#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*/ 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);
uint32_t c2_data_read(int bytes) {
  c2_pulse();
  gpio_output(4, 13);
  c2_send(0, 2);
  c2_send(bytes - 1, 2);
  gpio_input(4, 13);
  c2_pulse();
  while (!c2_recv(1))
    ;
  return c2_recv(8 * bytes);
}


x86 assembly (clang, -O0):
<c2_data_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <c2_pulse@plt>
mov    $0x4,%edi
mov    $0xd,%esi
call   1060 <gpio_output@plt>
xor    %edi,%edi
mov    $0x2,%esi
call   1070 <c2_send@plt>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    $0x2,%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    11c2 <c2_data_read+0x72>
jmp    11c7 <c2_data_read+0x77>
jmp    11a3 <c2_data_read+0x53>
mov    -0x4(%rbp),%edi
shl    $0x3,%edi
call   1050 <c2_recv@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c2_data_read>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <c2_pulse@plt>
mov    $0x4,%edi
mov    $0xd,%esi
call   1060 <gpio_output@plt>
xor    %edi,%edi
mov    $0x2,%esi
call   1070 <c2_send@plt>
lea    -0x1(%rbx),%edi
mov    $0x2,%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     11a0 <c2_data_read+0x50>
shl    $0x3,%ebx
mov    %ebx,%edi
pop    %rbx
jmp    1050 <c2_recv@plt>

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

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