#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*/ bzero(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int write(int, char *, int);
int readWrite(int fd) {
  int n;
  char buffer[256];
  bzero(buffer, 256);
  n = read(fd, buffer, 255);
  if (n < 0)
    return n;
  printf("Here is the message: %s\n", buffer);
  n = write(fd, "I got your message", 18);
  if (n < 0)
    return n;
}


x86 assembly (clang, -O0):
<readWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1060 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    118b <readWrite+0x4b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <readWrite+0x85>
lea    -0x110(%rbp),%rsi
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xe71(%rip),%rsi
mov    $0x12,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11c5 <readWrite+0x85>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readWrite>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   1060 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xff,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1191 <readWrite+0x51>
lea    0xe8a(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
lea    0xe94(%rip),%rsi
mov    %ebx,%edi
mov    $0x12,%edx
call   1030 <write@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Here is the message: %s\0A\00"
@.str.1 = [19 x i8] c"I got your message\00"
define i32 @readWrite(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
store i32 %0, i32* %3
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 256)
%8 = load i32, i32* %3
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 255)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load i32, i32* %4
store i32 %14, i32* %2
br label %24
15: ; preds = %1
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %3
%19 = call i32 @write(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %24
24: ; preds = %13, %22, %15
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [25 x i8] c"Here is the message: %s\0A\00"
@.str.1 = [19 x i8] c"I got your message\00"
define i32 @readWrite(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @bzero(i8* %3, i32 256)
%5 = call i32 @read(i32 %0, i8* %3, i32 255)
%6 = icmp slt i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %3)
%9 = call i32 @write(i32 %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 18)
br label %10
10: ; preds = %7, %1
%11 = phi i32 [ %5, %1 ], [ %9, %7 ]
ret i32 %11
}