#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*/ error(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int write(int, char *, int);
void dostuff(int sock) {
  int n;
  char buffer[256];
  bzero(buffer, 256);
  n = read(sock, buffer, 255);
  if (n < 0)
    error("ERROR reading from socket");
  printf("Here is the message: %s\n", buffer);
  n = write(sock, "I got your message", 18);
  if (n < 0)
    error("ERROR writing to socket");
}


x86 assembly (clang, -O0):
<dostuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1070 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    119c <dostuff+0x4c>
lea    0xe69(%rip),%rdi
call   1060 <error@plt>
lea    -0x110(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    0xe7a(%rip),%rsi
mov    $0x12,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11dc <dostuff+0x8c>
lea    0xe6f(%rip),%rdi
call   1060 <error@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dostuff>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   1070 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xff,%edx
call   1050 <read@plt>
test   %eax,%eax
jns    118b <dostuff+0x3b>
lea    0xe7a(%rip),%rdi
call   1060 <error@plt>
lea    0xe88(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
lea    0xe92(%rip),%rsi
mov    %ebx,%edi
mov    $0x12,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    11bd <dostuff+0x6d>
lea    0xe8e(%rip),%rdi
call   1060 <error@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [25 x i8] c"Here is the message: %s\0A\00"
@.str.2 = [19 x i8] c"I got your message\00"
@.str.3 = [24 x i8] c"ERROR writing to socket\00"
define void @dostuff(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 %7, label %9
7: ; preds = %1
%8 = tail call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%11 = call i32 @write(i32 %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 18)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
ret void
}