#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 */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
char *get_request(int client) {
  static char buffer[8192 + 1];
  char *request = "this is a test";
  int nread;
  while (1) {
    nread = recv(client, buffer, 8192, 0);
    if (nread < 0) {
      if (errno == EINTR) {
        continue;
      } else {
        return "";
      }
    } else if (nread == 0) {
      return "";
    }
    request = buffer;
    break;
  }
  printf("%s\n", request);
  return request;
}


x86 assembly (clang, -O0):
<get_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
lea    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    0x2f00(%rip),%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1188 <get_request+0x68>
mov    0x2e80(%rip),%rax
mov    (%rax),%rax
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%rax
jne    1178 <get_request+0x58>
jmp    1136 <get_request+0x16>
lea    0xe93(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ca <get_request+0xaa>
cmpl   $0x0,-0x1c(%rbp)
jne    11a2 <get_request+0x82>
lea    0xe79(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ca <get_request+0xaa>
jmp    11a7 <get_request+0x87>
lea    0x2e92(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_request>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebp
lea    0x2f0f(%rip),%r15
mov    0x2ea8(%rip),%r12
mov    0x2e99(%rip),%rbx
lea    0xebd(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jns    1170 <get_request+0x50>
mov    (%r12),%rax
cmp    (%rbx),%rax
je     1150 <get_request+0x30>
jmp    1184 <get_request+0x64>
je     1184 <get_request+0x64>
lea    0xe87(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %r15,%r14
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@get_request.buffer = internal global [8193 x i8] zeroinitializer
@.str = [15 x i8] c"this is a test\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [4 x i8] c"%s\0A\00"
define i8* @get_request(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %4
br label %6
6: ; preds = %1, %15
%7 = load i32, i32* %3
%8 = call i32 @recv(i32 %7, i8* getelementptr inbounds ([8193 x i8], [8193 x i8]* @get_request.buffer, i64 0, i64 0), i32 8192, i32 0)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
br label %6
16: ; preds = %11
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %27
17: ; preds = %6
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %27
21: ; preds = %17
br label %22
22: ; preds = %21
store i8* getelementptr inbounds ([8193 x i8], [8193 x i8]* @get_request.buffer, i64 0, i64 0), i8** %4
br label %23
23: ; preds = %22
%24 = load i8*, i8** %4
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %4
store i8* %26, i8** %2
br label %27
27: ; preds = %23, %20, %16
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@get_request.buffer = internal global [8193 x i8] zeroinitializer
@errno = global i64 0
@EINTR = global i64 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [4 x i8] c"%s\0A\00"
define i8* @get_request(i32 %0) {
br label %2
2: ; preds = %5, %1
%3 = tail call i32 @recv(i32 %0, i8* getelementptr inbounds ([8193 x i8], [8193 x i8]* @get_request.buffer, i64 0, i64 0), i32 8192, i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @EINTR
%8 = icmp eq i64 %6, %7
br i1 %8, label %2, label %13
9: ; preds = %2
%10 = icmp eq i32 %3, 0
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8193 x i8], [8193 x i8]* @get_request.buffer, i64 0, i64 0))
br label %13
13: ; preds = %5, %9, %11
%14 = phi i8* [ getelementptr inbounds ([8193 x i8], [8193 x i8]* @get_request.buffer, i64 0, i64 0), %11 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %5 ]
ret i8* %14
}