#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 atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(void *);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
void *server_thread_func(void *client_sockfd_ptr) {
  int sock = *(int *)client_sockfd_ptr;
  char write_message[65536] = {1};
  char read_message[64] = {'\0'};
  int len;
  int data_size;
  free(client_sockfd_ptr);
  len = recv(sock, read_message, 64, 0);
  if (len <= 0) {
    close(sock);
    return ((void *)0);
  }
  data_size = atoi(read_message) * 1024;
  while (data_size > 0) {
    len = (65536 < data_size) ? 65536 : data_size;
    data_size -= send(sock, write_message, len, 0);
  }
  close(sock);
  return ((void *)0);
}


x86 assembly (clang, -O0):
<server_thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10070,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x10020(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1060 <memset@plt>
movb   $0x1,-0x10020(%rbp)
lea    -0x10060(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
lea    -0x10060(%rbp),%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x10064(%rbp)
cmpl   $0x0,-0x10064(%rbp)
jg     11ec <server_thread_func+0x8c>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    1286 <server_thread_func+0x126>
lea    -0x10060(%rbp),%rdi
call   1080 <atoi@plt>
shl    $0xa,%eax
mov    %eax,-0x10068(%rbp)
cmpl   $0x0,-0x10068(%rbp)
jle    1276 <server_thread_func+0x116>
mov    $0x10000,%eax
cmp    -0x10068(%rbp),%eax
jge    122f <server_thread_func+0xcf>
mov    $0x10000,%eax
mov    %eax,-0x1006c(%rbp)
jmp    123b <server_thread_func+0xdb>
mov    -0x10068(%rbp),%eax
mov    %eax,-0x1006c(%rbp)
mov    -0x1006c(%rbp),%eax
mov    %eax,-0x10064(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10020(%rbp),%rsi
mov    -0x10064(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rax,%rcx
movslq -0x10068(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x10068(%rbp)
jmp    1201 <server_thread_func+0xa1>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_thread_func>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10040,%rsp
mov    %rdi,%rbp
mov    (%rdi),%ebx
lea    0x40(%rsp),%rdi
mov    $0x10000,%edx
xor    %esi,%esi
call   1060 <memset@plt>
movb   $0x1,0x40(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
jle    11f0 <server_thread_func+0x90>
mov    %rsp,%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    11f0 <server_thread_func+0x90>
mov    %eax,%ebp
shl    $0xa,%ebp
lea    0x40(%rsp),%r14
nop
cmp    $0x10000,%ebp
mov    $0x10000,%edx
cmovb  %ebp,%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
call   1050 <send@plt>
sub    %eax,%ebp
test   %ebp,%ebp
jg     11d0 <server_thread_func+0x70>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10040,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @server_thread_func(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [65536 x i8]
%6 = alloca [64 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
store i32 %11, i32* %4
%12 = bitcast [65536 x i8]* %5 to i8*
%13 = bitcast i8* %12 to <{ i8, [65535 x i8] }>*
%14 = getelementptr inbounds <{ i8, [65535 x i8] }>, <{ i8, [65535 x i8] }>* %13, i32 0, i32 0
store i8 1, i8* %14
%15 = bitcast [64 x i8]* %6 to i8*
%16 = load i8*, i8** %3
%17 = call i32 @free(i8* %16)
%18 = load i32, i32* %4
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%20 = call i32 @recv(i32 %18, i8* %19, i32 64, i32 0)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp sle i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %1
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
store i8* null, i8** %2
br label %52
26: ; preds = %1
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%28 = call i32 @atoi(i8* %27)
%29 = mul nsw i32 %28, 1024
store i32 %29, i32* %8
br label %30
30: ; preds = %39, %26
%31 = load i32, i32* %8
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %49
33: ; preds = %30
%34 = load i32, i32* %8
%35 = icmp slt i32 65536, %34
br i1 %35, label %36, label %37
36: ; preds = %33
br label %39
37: ; preds = %33
%38 = load i32, i32* %8
br label %39
39: ; preds = %37, %36
%40 = phi i32 [ 65536, %36 ], [ %38, %37 ]
store i32 %40, i32* %7
%41 = load i32, i32* %4
%42 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
%43 = load i32, i32* %7
%44 = call i64 @send(i32 %41, i8* %42, i32 %43, i32 0)
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = sub nsw i64 %46, %44
%48 = trunc i64 %47 to i32
store i32 %48, i32* %8
br label %30
49: ; preds = %30
%50 = load i32, i32* %4
%51 = call i32 @close(i32 %50)
store i8* null, i8** %2
br label %52
52: ; preds = %49, %23
%53 = load i8*, i8** %2
ret i8* %53
}

LLVM IR (-O2):
define noalias i8* @server_thread_func(i8* nocapture %0) {
%2 = alloca [65536 x i8]
%3 = alloca [64 x i8]
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %2, i64 0, i64 0
store i8 1, i8* %6
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%8 = tail call i32 @free(i8* %0)
%9 = call i32 @recv(i32 %5, i8* %7, i32 64, i32 0)
%10 = icmp slt i32 %9, 1
br i1 %10, label %24, label %11
11: ; preds = %1
%12 = call i32 @atoi(i8* %7)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = shl nsw i32 %12, 10
br label %16
16: ; preds = %14, %16
%17 = phi i32 [ %22, %16 ], [ %15, %14 ]
%18 = icmp ult i32 %17, 65536
%19 = select i1 %18, i32 %17, i32 65536
%20 = call i64 @send(i32 %5, i8* %6, i32 %19, i32 0)
%21 = trunc i64 %20 to i32
%22 = sub i32 %17, %21
%23 = icmp sgt i32 %22, 0
br i1 %23, label %16, label %24
24: ; preds = %16, %11, %1
%25 = call i32 @close(i32 %5)
ret i8* null
}