#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
void block_server(int *sock) {
  char buff[5000000];
  int n;
  do {
    n = read(*sock, buff, 5000000);
    printf("gets past first send\n");
    if (n < 0) {
      perror("read() failed");
      exit(EXIT_FAILURE);
    } else {
      buff[n] = '\0';
      printf("%s", buff);
    }
  } while (n > 0);
}


x86 assembly (clang, -O0):
<block_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4c4b60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x4c4b50(%rbp),%rsi
mov    $0x4c4b40,%edx
call   1040 <read@plt>
mov    %eax,-0x4c4b54(%rbp)
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x4c4b54(%rbp)
jge    11a1 <block_server+0x61>
lea    0xe88(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movslq -0x4c4b54(%rbp),%rax
movb   $0x0,-0x4c4b50(%rbp,%rax,1)
lea    -0x4c4b50(%rbp),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <block_server+0x8a>
cmpl   $0x0,-0x4c4b54(%rbp)
jg     114f <block_server+0xf>
add    $0x4c4b60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<block_server>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x4c4b40,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
lea    0xea5(%rip),%r15
lea    0xe9b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x4c4b40,%edx
call   1050 <read@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <puts@plt>
test   %ebp,%ebp
js     11c5 <block_server+0x75>
mov    %ebp,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jne    1180 <block_server+0x30>
add    $0x4c4b40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe34(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"gets past first send\0A\00"
@.str.1 = [14 x i8] c"read() failed\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define void @block_server(i32* %0) {
%2 = alloca i32*
%3 = alloca [5000000 x i8]
%4 = alloca i32
store i32* %0, i32** %2
br label %5
5: ; preds = %24, %1
%6 = load i32*, i32** %2
%7 = load i32, i32* %6
%8 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %3, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 5000000)
store i32 %9, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %5
%14 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %5
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %3, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %3, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %17
br label %24
24: ; preds = %23
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 0
br i1 %26, label %5, label %27
27: ; preds = %24
ret void
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"read() failed\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@str = [21 x i8] c"gets past first send\00"
define void @block_server(i32* nocapture %0) {
%2 = alloca [5000000 x i8]
%3 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %13, %1
%5 = load i32, i32* %0
%6 = call i32 @read(i32 %5, i8* %3, i32 5000000)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%8 = icmp slt i32 %6, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %4
%14 = zext i32 %6 to i64
%15 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %2, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%17 = icmp eq i32 %6, 0
br i1 %17, label %18, label %4
18: ; preds = %13
ret void
}