#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*/ close(int);
int recieve_from_socket(int, char *);
int send_to_socket(int, int *, int);
int split_and_insert(char *, int *);
int main_loop(int listenfd) {
  char buff[1024000];
  int data[10240];
  int ret, num;
  int connfd;
  while (1) {
    connfd = recieve_from_socket(listenfd, buff);
    if (connfd < 0)
      continue;
    num = split_and_insert(buff, data);
    ret = send_to_socket(connfd, data, num);
    close(connfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x104020,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xfa010(%rbp),%rsi
call   1060 <recieve_from_socket@plt>
mov    %eax,-0x10401c(%rbp)
cmpl   $0x0,-0x10401c(%rbp)
jge    1175 <main_loop+0x35>
jmp    114e <main_loop+0xe>
lea    -0xfa010(%rbp),%rdi
lea    -0x104010(%rbp),%rsi
call   1030 <split_and_insert@plt>
mov    %eax,-0x104018(%rbp)
mov    -0x10401c(%rbp),%edi
lea    -0x104010(%rbp),%rsi
mov    -0x104018(%rbp),%edx
call   1050 <send_to_socket@plt>
mov    %eax,-0x104014(%rbp)
mov    -0x10401c(%rbp),%edi
call   1040 <close@plt>
jmp    114e <main_loop+0xe>

x86 assembly (clang, -O2):
<main_loop>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x104008,%rsp
mov    %edi,%ebx
lea    0xa000(%rsp),%r14
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <recieve_from_socket@plt>
test   %eax,%eax
js     1160 <main_loop+0x20>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <split_and_insert@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <send_to_socket@plt>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    1160 <main_loop+0x20>

LLVM IR (-O0):
define i32 @main_loop(i32 %0) {
%2 = alloca i32
%3 = alloca [1024000 x i8]
%4 = alloca [10240 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
br label %8
8: ; preds = %1, %14, %15
%9 = load i32, i32* %2
%10 = getelementptr inbounds [1024000 x i8], [1024000 x i8]* %3, i64 0, i64 0
%11 = call i32 @recieve_from_socket(i32 %9, i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %8
br label %8
15: ; preds = %8
%16 = getelementptr inbounds [1024000 x i8], [1024000 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [10240 x i32], [10240 x i32]* %4, i64 0, i64 0
%18 = call i32 @split_and_insert(i8* %16, i32* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %7
%20 = getelementptr inbounds [10240 x i32], [10240 x i32]* %4, i64 0, i64 0
%21 = load i32, i32* %6
%22 = call i32 @send_to_socket(i32 %19, i32* %20, i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %7
%24 = call i32 @close(i32 %23)
br label %8
}

LLVM IR (-O2):
define i32 @main_loop(i32 %0) {
%2 = alloca [1024000 x i8]
%3 = alloca [10240 x i32]
%4 = getelementptr inbounds [1024000 x i8], [1024000 x i8]* %2, i64 0, i64 0
%5 = bitcast [10240 x i32]* %3 to i8*
%6 = getelementptr inbounds [10240 x i32], [10240 x i32]* %3, i64 0, i64 0
br label %7
7: ; preds = %14, %1
%8 = call i32 @recieve_from_socket(i32 %0, i8* %4)
%9 = icmp slt i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = call i32 @split_and_insert(i8* %4, i32* %6)
%12 = call i32 @send_to_socket(i32 %8, i32* %6, i32 %11)
%13 = call i32 @close(i32 %8)
br label %14
14: ; preds = %10, %7
br label %7
}