#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 /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ system(char *);
int write(int, char *, int);
void dostuff(int sock) {
  int n;
  char buffer[256];
  char cmd[256];
  bzero(buffer, 256);
  n = read(sock, buffer, 255);
  if (n < 0)
    error("ERROR reading from socket");
  printf("Message from client: %s\n", buffer);
  sprintf(cmd, "wall %s", buffer);
  system(cmd);
  n = write(sock, "ACK for Client", 15);
  if (n < 0)
    error("ERROR writing to socket");
}


x86 assembly (clang, -O0):
<dostuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1080 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11bc <dostuff+0x4c>
lea    0xe49(%rip),%rdi
call   1070 <error@plt>
lea    -0x110(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
lea    -0x210(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xe4f(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x210(%rbp),%rdi
call   1040 <system@plt>
mov    -0x4(%rbp),%edi
lea    0xe3c(%rip),%rsi
mov    $0xf,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1222 <dostuff+0xb2>
lea    0xe2d(%rip),%rdi
call   1070 <error@plt>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dostuff>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %edi,%r14d
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1080 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1060 <read@plt>
test   %eax,%eax
jns    11ae <dostuff+0x3e>
lea    0xe57(%rip),%rdi
call   1070 <error@plt>
lea    0xe65(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xe6c(%rip),%rsi
lea    0x100(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <system@plt>
lea    0xe52(%rip),%rsi
mov    %r14d,%edi
mov    $0xf,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    1206 <dostuff+0x96>
lea    0xe49(%rip),%rdi
call   1070 <error@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [25 x i8] c"Message from client: %s\0A\00"
@.str.2 = [8 x i8] c"wall %s\00"
@.str.3 = [15 x i8] c"ACK for Client\00"
@.str.4 = [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]
%5 = alloca [256 x i8]
store i32 %0, i32* %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 256)
%8 = load i32, i32* %2
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 255)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%22 = call i32 @system(i8* %21)
%23 = load i32, i32* %2
%24 = call i32 @write(i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 15)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %15
%28 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27, %15
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [25 x i8] c"Message from client: %s\0A\00"
@.str.2 = [8 x i8] c"wall %s\00"
@.str.3 = [15 x i8] c"ACK for Client\00"
@.str.4 = [24 x i8] c"ERROR writing to socket\00"
define void @dostuff(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = call i32 @bzero(i8* %4, i32 256)
%7 = call i32 @read(i32 %0, i8* %4, i32 255)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%13 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%14 = call i32 @system(i8* %5)
%15 = call i32 @write(i32 %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 15)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
ret void
}