#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;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int, int, int, int, int, int, int, int,
                          int, int, int);
int read(int, int *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
void do_read(int fd) {
  int i;
  char tx = 0xa1;
  uint8_t buf[2000] = {0};
  uint32_t size = sizeof(buf);
  while (1) {
    write(fd, &tx, 1);
    size = read(fd, buf, size);
    printf("read:%d,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n", size, buf[0], buf[1],
           buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9],
           buf[1999]);
    usleep(20000);
  }
}


x86 assembly (clang, -O0):
<do_read>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1f90,%rsp
mov    %edi,-0x24(%rbp)
movb   $0xa1,-0x29(%rbp)
lea    -0x1f70(%rbp),%rdi
xor    %esi,%esi
mov    $0x1f40,%edx
call   1050 <memset@plt>
movl   $0x1f40,-0x1f74(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
lea    -0x1f70(%rbp),%rsi
mov    -0x1f74(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x1f74(%rbp)
mov    -0x1f74(%rbp),%esi
mov    -0x1f70(%rbp),%edx
mov    -0x1f6c(%rbp),%ecx
mov    -0x1f68(%rbp),%r8d
mov    -0x1f64(%rbp),%r9d
mov    -0x1f60(%rbp),%r12d
mov    -0x1f5c(%rbp),%r15d
mov    -0x1f58(%rbp),%r14d
mov    -0x1f54(%rbp),%ebx
mov    -0x1f50(%rbp),%r11d
mov    -0x1f4c(%rbp),%r10d
mov    -0x34(%rbp),%eax
lea    0xdfb(%rip),%rdi
mov    %r12d,(%rsp)
mov    %r15d,0x8(%rsp)
mov    %r14d,0x10(%rsp)
mov    %ebx,0x18(%rsp)
mov    %r11d,0x20(%rsp)
mov    %r10d,0x28(%rsp)
mov    %eax,0x30(%rsp)
call   1040 <printf@plt>
mov    $0x4e20,%edi
call   1070 <usleep@plt>
jmp    1186 <do_read+0x36>

x86 assembly (clang, -O2):
<do_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f58,%rsp
mov    %edi,%r13d
movb   $0xa1,0xf(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x1f40,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x1f40,%r14d
mov    %r13d,%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r13d,%edi
lea    0x10(%rsp),%rsi
mov    %r14d,%edx
call   1060 <read@plt>
mov    %eax,%r14d
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    0x18(%rsp),%r8d
mov    0x1c(%rsp),%r9d
mov    0x20(%rsp),%r10d
mov    0x24(%rsp),%r11d
mov    0x28(%rsp),%ebp
mov    0x2c(%rsp),%eax
mov    0x30(%rsp),%ebx
mov    0x34(%rsp),%r15d
mov    0x1f4c(%rsp),%r12d
sub    $0x8,%rsp
lea    0xe1b(%rip),%rdi
mov    %r14d,%esi
push   %r12
push   %r15
push   %rbx
push   %rax
push   %rbp
push   %r11
push   %r10
call   1040 <printf@plt>
add    $0x40,%rsp
mov    $0x4e20,%edi
call   1070 <usleep@plt>
jmp    1180 <do_read+0x30>

LLVM IR (-O0):
@.str = [42 x i8] c"read:%d,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\0A\00"
define void @do_read(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca [2000 x i32]
%6 = alloca i32
store i32 %0, i32* %2
store i8 -95, i8* %4
%7 = bitcast [2000 x i32]* %5 to i8*
store i32 8000, i32* %6
br label %8
8: ; preds = %1, %8
%9 = load i32, i32* %2
%10 = call i32 @write(i32 %9, i8* %4, i32 1)
%11 = load i32, i32* %2
%12 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 0
%13 = load i32, i32* %6
%14 = call i32 @read(i32 %11, i32* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 2
%21 = load i32, i32* %20
%22 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 3
%23 = load i32, i32* %22
%24 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 4
%25 = load i32, i32* %24
%26 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 5
%27 = load i32, i32* %26
%28 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 6
%29 = load i32, i32* %28
%30 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 7
%31 = load i32, i32* %30
%32 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 8
%33 = load i32, i32* %32
%34 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 9
%35 = load i32, i32* %34
%36 = getelementptr inbounds [2000 x i32], [2000 x i32]* %5, i64 0, i64 1999
%37 = load i32, i32* %36
%38 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %17, i32 %19, i32 %21, i32 %23, i32 %25, i32 %27, i32 %29, i32 %31, i32 %33, i32 %35, i32 %37)
%39 = call i32 @usleep(i32 20000)
br label %8
}

LLVM IR (-O2):
@.str = [42 x i8] c"read:%d,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\0A\00"
define void @do_read(i32 %0) {
%2 = alloca i8
%3 = alloca [2000 x i32]
store i8 -95, i8* %2
%4 = bitcast [2000 x i32]* %3 to i8*
%5 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 0
%6 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 1
%7 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 2
%8 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 3
%9 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 4
%10 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 5
%11 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 6
%12 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 7
%13 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 8
%14 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 9
%15 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 1999
br label %16
16: ; preds = %16, %1
%17 = phi i32 [ 8000, %1 ], [ %19, %16 ]
%18 = call i32 @write(i32 %0, i8* %2, i32 1)
%19 = call i32 @read(i32 %0, i32* %5, i32 %17)
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = load i32, i32* %11
%27 = load i32, i32* %12
%28 = load i32, i32* %13
%29 = load i32, i32* %14
%30 = load i32, i32* %15
%31 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20, i32 %21, i32 %22, i32 %23, i32 %24, i32 %25, i32 %26, i32 %27, i32 %28, i32 %29, i32 %30)
%32 = tail call i32 @usleep(i32 20000)
br label %16
}