#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*/ exit(int);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *);
int read(int, char *, int);
int write(int, char *, int);
int doprocessing(int sock) {
  int n;
  char buffer[256];
  bzero(buffer, 256);
  n = write(sock, "> ", 2);
  if (n < 0) {
    perror("ERROR writing to socket");
    exit(1);
  }
  n = read(sock, buffer, 255);
  if (n < 0) {
    perror("ERROR reading from socket");
    exit(1);
  }
  printf("pid:%d Message: %s\n", getpid(), buffer);
  if (buffer[0] == 'X')
    return 0;
  else
    return 1;
}


x86 assembly (clang, -O0):
<doprocessing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1080 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    0xe67(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11c6 <doprocessing+0x56>
lea    0xe4c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1060 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11fd <doprocessing+0x8d>
lea    0xe2d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    -0x110(%rbp),%rdx
lea    0xe21(%rip),%rdi
call   1050 <printf@plt>
movsbl -0x110(%rbp),%eax
cmp    $0x58,%eax
jne    1235 <doprocessing+0xc5>
movl   $0x0,-0x4(%rbp)
jmp    123c <doprocessing+0xcc>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doprocessing>:
push   %rbx
sub    $0x100,%rsp
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1080 <bzero@plt>
lea    0xe72(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <write@plt>
test   %eax,%eax
js     11db <doprocessing+0x6b>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xff,%edx
call   1060 <read@plt>
test   %eax,%eax
js     11e4 <doprocessing+0x74>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe76(%rip),%rdi
mov    %rsp,%rdx
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
cmpb   $0x58,(%rsp)
setne  %al
add    $0x100,%rsp
pop    %rbx
ret
lea    0xe21(%rip),%rdi
jmp    11eb <doprocessing+0x7b>
lea    0xe30(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"> \00"
@.str.1 = [24 x i8] c"ERROR writing to socket\00"
@.str.2 = [26 x i8] c"ERROR reading from socket\00"
@.str.3 = [20 x i8] c"pid:%d Message: %s\0A\00"
define i32 @doprocessing(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 = call i32 @write(i32 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = load i32, i32* %3
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 255)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = call i32 (...) @getpid()
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %25, i8* %26)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 88
br i1 %31, label %32, label %33
32: ; preds = %24
store i32 0, i32* %2
br label %34
33: ; preds = %24
store i32 1, i32* %2
br label %34
34: ; preds = %33, %32
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"> \00"
@.str.1 = [24 x i8] c"ERROR writing to socket\00"
@.str.2 = [26 x i8] c"ERROR reading from socket\00"
@.str.3 = [20 x i8] c"pid:%d Message: %s\0A\00"
define i32 @doprocessing(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 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = call i32 @read(i32 %0, i8* %3, i32 255)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %10
%17 = tail call i32 (...) @getpid()
%18 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %17, i8* %3)
%19 = load i8, i8* %3
%20 = icmp ne i8 %19, 88
%21 = zext i1 %20 to i32
ret i32 %21
}