#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 /*<<< orphan*/ buf;

/* Variables and functions */
int block_on_read(int, float);
int /*<<< orphan*/ myexit(int);
int /*<<< orphan*/ perror(char *);
int recv(int, unsigned char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, unsigned char *, int);
void request_content(int sock,
                     int (*sendproc)(int, char *, unsigned char *, int),
                     char *dest, unsigned char *out, int len, float wait) {
  unsigned char buf[64 * 1024];
  int len2 = sendproc(sock, dest, out, len), rc;
  if (len2 < 0) {
    perror("sendto");
    myexit(1);
  }
  rc = block_on_read(sock, wait);
  if (rc == 1) {
    len2 = recv(sock, buf, sizeof(buf), 0);
    if (len2 > 0) {
      write(1, buf, len2);
      myexit(0);
    }
  }
}


x86 assembly (clang, -O0):
<request_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10040,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movss  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   *%rax
mov    %eax,-0x10034(%rbp)
cmpl   $0x0,-0x10034(%rbp)
jge    11b0 <request_content+0x60>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1060 <myexit@plt>
mov    -0x4(%rbp),%edi
movss  -0x28(%rbp),%xmm0
call   1040 <block_on_read@plt>
mov    %eax,-0x10038(%rbp)
cmpl   $0x1,-0x10038(%rbp)
jne    121c <request_content+0xcc>
mov    -0x4(%rbp),%edi
lea    -0x10030(%rbp),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x10034(%rbp)
cmpl   $0x0,-0x10034(%rbp)
jle    1217 <request_content+0xc7>
lea    -0x10030(%rbp),%rsi
mov    -0x10034(%rbp),%edx
mov    $0x1,%edi
call   1050 <write@plt>
xor    %edi,%edi
call   1060 <myexit@plt>
jmp    121c <request_content+0xcc>
add    $0x10040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<request_content>:
push   %rbx
sub    $0x10010,%rsp
movss  %xmm0,0xc(%rsp)
mov    %rsi,%rax
mov    %edi,%ebx
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8d,%ecx
call   *%rax
test   %eax,%eax
js     11bc <request_content+0x6c>
mov    %ebx,%edi
movss  0xc(%rsp),%xmm0
call   1040 <block_on_read@plt>
cmp    $0x1,%eax
jne    11b3 <request_content+0x63>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    11b3 <request_content+0x63>
lea    0x10(%rsp),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1050 <write@plt>
xor    %edi,%edi
call   1060 <myexit@plt>
add    $0x10010,%rsp
pop    %rbx
ret
lea    0xe3d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1060 <myexit@plt>
jmp    1172 <request_content+0x22>

LLVM IR (-O0):
@.str = [7 x i8] c"sendto\00"
define void @request_content(i32 %0, i32 (i32, i8*, i8*, i32)* %1, i8* %2, i8* %3, i32 %4, float %5) {
%7 = alloca i32
%8 = alloca i32 (i32, i8*, i8*, i32)*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca float
%13 = alloca [65536 x i8]
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %7
store i32 (i32, i8*, i8*, i32)* %1, i32 (i32, i8*, i8*, i32)** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store float %5, float* %12
%16 = load i32 (i32, i8*, i8*, i32)*, i32 (i32, i8*, i8*, i32)** %8
%17 = load i32, i32* %7
%18 = load i8*, i8** %9
%19 = load i8*, i8** %10
%20 = load i32, i32* %11
%21 = call i32 %16(i32 %17, i8* %18, i8* %19, i32 %20)
store i32 %21, i32* %14
%22 = load i32, i32* %14
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %6
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @myexit(i32 1)
br label %27
27: ; preds = %24, %6
%28 = load i32, i32* %7
%29 = load float, float* %12
%30 = call i32 @block_on_read(i32 %28, float %29)
store i32 %30, i32* %15
%31 = load i32, i32* %15
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %45
33: ; preds = %27
%34 = load i32, i32* %7
%35 = getelementptr inbounds [65536 x i8], [65536 x i8]* %13, i64 0, i64 0
%36 = call i32 @recv(i32 %34, i8* %35, i32 65536, i32 0)
store i32 %36, i32* %14
%37 = load i32, i32* %14
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %33
%40 = getelementptr inbounds [65536 x i8], [65536 x i8]* %13, i64 0, i64 0
%41 = load i32, i32* %14
%42 = call i32 @write(i32 1, i8* %40, i32 %41)
%43 = call i32 @myexit(i32 0)
br label %44
44: ; preds = %39, %33
br label %45
45: ; preds = %44, %27
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"sendto\00"
define void @request_content(i32 %0, i32 (i32, i8*, i8*, i32)* nocapture %1, i8* %2, i8* %3, i32 %4, float %5) {
%7 = alloca [65536 x i8]
%8 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%9 = tail call i32 %1(i32 %0, i8* %2, i8* %3, i32 %4)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @myexit(i32 1)
br label %14
14: ; preds = %11, %6
%15 = tail call i32 @block_on_read(i32 %0, float %5)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = call i32 @recv(i32 %0, i8* %8, i32 65536, i32 0)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @write(i32 1, i8* %8, i32 %18)
%22 = call i32 @myexit(i32 0)
br label %23
23: ; preds = %17, %20, %14
ret void
}