#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ close_connection(int);
int errno;
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
void service_request(int request) {
  char *buffer = malloc(256 * sizeof(char));
  ssize_t bytes_read;
  while ((bytes_read = read(request, buffer, sizeof(buffer))) > 1) {
    for (int character = 0; character < bytes_read; character++) {
      printf("%c", *(buffer + character));
    }
  }
  if (bytes_read == -1) {
    printf("Error occurred reading request file descriptor. %i", errno);
  }
  free(buffer);
  close_connection(request);
}


x86 assembly (clang, -O0):
<service_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x1,%eax
jle    11c4 <service_request+0x74>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bf <service_request+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118d <service_request+0x3d>
jmp    1169 <service_request+0x19>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e3 <service_request+0x93>
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
call   1050 <close_connection@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<service_request>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %r14d,%edi
mov    %rax,%rsi
mov    $0x8,%edx
call   1060 <read@plt>
cmp    $0x2,%eax
jl     11cb <service_request+0x7b>
lea    0xe7c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <service_request+0x50>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x8,%edx
call   1060 <read@plt>
cmp    $0x2,%eax
jge    1190 <service_request+0x40>
cmp    $0xffffffff,%eax
jne    11e5 <service_request+0x95>
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <close_connection@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [51 x i8] c"Error occurred reading request file descriptor. %i\00"
@errno = global i32 0
define void @service_request(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i8* @malloc(i32 256)
store i8* %6, i8** %3
br label %7
7: ; preds = %28, %1
%8 = load i32, i32* %2
%9 = load i8*, i8** %3
%10 = call i32 @read(i32 %8, i8* %9, i32 8)
store i32 %10, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %29
12: ; preds = %7
store i32 0, i32* %5
br label %13
13: ; preds = %25, %12
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %17
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %13
28: ; preds = %13
br label %7
29: ; preds = %7
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* @errno
%34 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %29
%36 = load i8*, i8** %3
%37 = call i32 @free(i8* %36)
%38 = load i32, i32* %2
%39 = call i32 @close_connection(i32 %38)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [51 x i8] c"Error occurred reading request file descriptor. %i\00"
@errno = global i32 0
define void @service_request(i32 %0) {
%2 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%3 = tail call i32 @read(i32 %0, i8* %2, i32 8)
%4 = icmp sgt i32 %3, 1
br i1 %4, label %8, label %19
5: ; preds = %11
%6 = tail call i32 @read(i32 %0, i8* %2, i32 8)
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %19
8: ; preds = %1, %5
%9 = phi i32 [ %6, %5 ], [ %3, %1 ]
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ 0, %8 ], [ %17, %11 ]
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = add nuw nsw i64 %12, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %5, label %11
19: ; preds = %5, %1
%20 = phi i32 [ %3, %1 ], [ %6, %5 ]
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* @errno
%24 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %19
%26 = tail call i32 @free(i8* %2)
%27 = tail call i32 @close_connection(i32 %0)
ret void
}