#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*/ printf(char *, ...);
int read(int, void *, int);
void process_step(int fd) {
  static unsigned char rx_buffer[2048];
  if (fd != -1) {
    int rx_length = read(fd, (void *)rx_buffer, 2048);
    if (rx_length < 0) {
      printf("no bytes to read (error)\n");
    } else if (rx_length == 0) {
      printf("zero bytes to read (empty)\n");
    } else {
      rx_buffer[rx_length] = '\0';
      printf("%s", rx_buffer);
    }
  } else {
    printf("nothing to read\n");
  }
}


x86 assembly (clang, -O0):
<process_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
je     11b4 <process_step+0x94>
mov    -0x4(%rbp),%edi
lea    0x2f01(%rip),%rsi
mov    $0x800,%edx
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1169 <process_step+0x49>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11af <process_step+0x8f>
cmpl   $0x0,-0x8(%rbp)
jne    1186 <process_step+0x66>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11aa <process_step+0x8a>
movslq -0x8(%rbp),%rcx
lea    0x2eaf(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0xe9a(%rip),%rdi
lea    0x2e9d(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11af <process_step+0x8f>
jmp    11c2 <process_step+0xa2>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_step>:
push   %rbx
cmp    $0xffffffff,%edi
je     1168 <process_step+0x38>
lea    0x2f13(%rip),%rbx
mov    %rbx,%rsi
mov    $0x800,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1175 <process_step+0x45>
je     1182 <process_step+0x52>
mov    %eax,%eax
movb   $0x0,(%rax,%rbx,1)
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1040 <printf@plt>
lea    0xe94(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
lea    0xeb2(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
lea    0xe8a(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@process_step.rx_buffer = internal global [2048 x i8] zeroinitializer
@.str = [26 x i8] c"no bytes to read (error)\0A\00"
@.str.1 = [28 x i8] c"zero bytes to read (empty)\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [17 x i8] c"nothing to read\0A\00"
define void @process_step(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, -1
br i1 %5, label %6, label %25
6: ; preds = %1
%7 = load i32, i32* %2
%8 = call i32 @read(i32 %7, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @process_step.rx_buffer, i64 0, i64 0), i32 2048)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %24
13: ; preds = %6
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %23
18: ; preds = %13
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* @process_step.rx_buffer, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @process_step.rx_buffer, i64 0, i64 0))
br label %23
23: ; preds = %18, %16
br label %24
24: ; preds = %23, %11
br label %27
25: ; preds = %1
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %24
ret void
}

LLVM IR (-O2):
@process_step.rx_buffer = internal global [2048 x i8] zeroinitializer
@.str.2 = [3 x i8] c"%s\00"
@str = [16 x i8] c"nothing to read\00"
@str.4 = [27 x i8] c"zero bytes to read (empty)\00"
@str.5 = [25 x i8] c"no bytes to read (error)\00"
define void @process_step(i32 %0) {
%2 = icmp eq i32 %0, -1
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = tail call i32 @read(i32 %0, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @process_step.rx_buffer, i64 0, i64 0), i32 2048)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
br label %18
8: ; preds = %3
%9 = icmp eq i32 %4, 0
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.4, i64 0, i64 0))
br label %18
12: ; preds = %8
%13 = zext i32 %4 to i64
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* @process_step.rx_buffer, i64 0, i64 %13
store i8 0, i8* %14
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @process_step.rx_buffer, i64 0, i64 0))
br label %18
16: ; preds = %1
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %6, %12, %10, %16
ret void
}