#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 BUFSIZ;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ memset(char *, int, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
void *server_thread_func(void *client_sockfd_ptr) {
  int i;
  int sock = *(int *)client_sockfd_ptr;
  char write_message[BUFSIZ + 1];
  char read_message[1024] = {0};
  int len;
  int data_size;
  free(client_sockfd_ptr);
  memset(write_message, 1, BUFSIZ);
  write_message[BUFSIZ] = '\0';
  len = recv(sock, read_message, 1024, 0);
  data_size = atoi(read_message);
  int loop = data_size * 1024 / BUFSIZ;
  for (i = 0; i < loop; i++) {
    send(sock, write_message, strlen(write_message), 0);
  }
  close(sock);
  return ((void *)0);
}


x86 assembly (clang, -O0):
<server_thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x438(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x438(%rbp),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1070 <memset@plt>
mov    -0x438(%rbp),%rax
mov    0x2de2(%rip),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x428(%rbp)
mov    -0x428(%rbp),%eax
shl    $0xa,%eax
mov    0x2d9d(%rip),%rcx
cltd
idivl  (%rcx)
mov    %eax,-0x42c(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x42c(%rbp),%eax
jge    129b <server_thread_func+0x12b>
mov    -0x438(%rbp),%rdi
mov    -0x10(%rbp),%eax
mov    %eax,-0x43c(%rbp)
call   1050 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1253 <server_thread_func+0xe3>
mov    -0x10(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_thread_func>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
mov    (%rdi),%r14d
mov    0x2e4f(%rip),%r13
mov    0x0(%r13),%eax
add    $0x1,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x430(%rbp),%r15
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    $0x1,%esi
call   1070 <memset@plt>
movslq 0x0(%r13),%rax
movb   $0x0,(%rax,%r12,1)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %r15,%rdi
call   1090 <atoi@plt>
shl    $0xa,%eax
cltd
idivl  0x0(%r13)
test   %eax,%eax
jle    122c <server_thread_func+0xbc>
mov    %eax,%ebx
nopl   0x0(%rax)
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
add    $0xffffffff,%ebx
jne    1210 <server_thread_func+0xa0>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@BUFSIZ = global i32 0
define noalias i8* @server_thread_func(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = load i32, i32* @BUFSIZ
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%10 = tail call i32 @free(i8* %0)
%11 = load i32, i32* @BUFSIZ
%12 = call i32 @memset(i8* %8, i32 1, i32 %11)
%13 = load i32, i32* @BUFSIZ
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %8, i64 %14
store i8 0, i8* %15
%16 = call i32 @recv(i32 %4, i8* %9, i32 1024, i32 0)
%17 = call i32 @atoi(i8* %9)
%18 = shl nsw i32 %17, 10
%19 = load i32, i32* @BUFSIZ
%20 = sdiv i32 %18, %19
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %1, %22
%23 = phi i32 [ %26, %22 ], [ 0, %1 ]
%24 = call i32 @strlen(i8* %8)
%25 = call i32 @send(i32 %4, i8* %8, i32 %24, i32 0)
%26 = add nuw nsw i32 %23, 1
%27 = icmp eq i32 %26, %20
br i1 %27, label %28, label %22
28: ; preds = %22, %1
%29 = call i32 @close(i32 %4)
ret i8* null
}