#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*/ msg;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strncat(char *, char *, int);
void *newSock(void *new_socket) {
  int recv_len;
  char buffer[(512)], msg[(512) * 3];
  int new_s = *(int *)new_socket;
  printf("Running a new thread now\n");
  while (recv_len = recv(new_s, buffer, (512), 0)) {
    if (recv_len < 0) {
      perror("Receive Error:");
      exit(1);
    }
    strncat(msg, buffer, (512));
    strncat(msg, buffer, (512));
    strncat(msg, buffer, (512));
    if ((send(new_s, msg, (512) * 3, 0)) < 0) {
      perror("Send error:");
      exit(1);
    }
    memset(msg, 0, sizeof(msg));
    memset(buffer, 0, sizeof(buffer));
  }
  close(new_s);
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<newSock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x824(%rbp)
lea    0xe4e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x824(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     12a8 <newSock+0x118>
cmpl   $0x0,-0x14(%rbp)
jge    11fc <newSock+0x6c>
lea    0xe2d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x820(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1070 <strncat@plt>
lea    -0x820(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1070 <strncat@plt>
lea    -0x820(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1070 <strncat@plt>
mov    -0x824(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x600,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    127d <newSock+0xed>
lea    0xdbb(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x600,%edx
call   1060 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
jmp    11b7 <newSock+0x27>
mov    -0x824(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newSock>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    (%rdi),%r14d
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1257 <newSock+0xc7>
lea    0x200(%rsp),%rbx
mov    %rsp,%rbp
nop
test   %eax,%eax
js     1272 <newSock+0xe2>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x200,%edx
call   1070 <strncat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x200,%edx
call   1070 <strncat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x200,%edx
call   1070 <strncat@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x600,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %rax,%rax
js     127b <newSock+0xeb>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x600,%edx
call   1060 <memset@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jne    11d0 <newSock+0x40>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %edi,%edi
call   1090 <pthread_exit@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd87(%rip),%rdi
jmp    1282 <newSock+0xf2>
lea    0xd8d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Running a new thread now\0A\00"
@.str.1 = [15 x i8] c"Receive Error:\00"
@.str.2 = [12 x i8] c"Send error:\00"
define i8* @newSock(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca [1536 x i8]
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to i32*
%10 = load i32, i32* %9
store i32 %10, i32* %7
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %40, %1
%13 = load i32, i32* %7
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%15 = call i32 @recv(i32 %13, i8* %14, i32 512, i32 0)
store i32 %15, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %45
17: ; preds = %12
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = getelementptr inbounds [1536 x i8], [1536 x i8]* %6, i64 0, i64 0
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%26 = call i32 @strncat(i8* %24, i8* %25, i32 512)
%27 = getelementptr inbounds [1536 x i8], [1536 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%29 = call i32 @strncat(i8* %27, i8* %28, i32 512)
%30 = getelementptr inbounds [1536 x i8], [1536 x i8]* %6, i64 0, i64 0
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%32 = call i32 @strncat(i8* %30, i8* %31, i32 512)
%33 = load i32, i32* %7
%34 = getelementptr inbounds [1536 x i8], [1536 x i8]* %6, i64 0, i64 0
%35 = call i64 @send(i32 %33, i8* %34, i32 1536, i32 0)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %23
%38 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %23
%41 = getelementptr inbounds [1536 x i8], [1536 x i8]* %6, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 1536)
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%44 = call i32 @memset(i8* %43, i32 0, i32 512)
br label %12
45: ; preds = %12
%46 = load i32, i32* %7
%47 = call i32 @close(i32 %46)
%48 = call i32 @pthread_exit(i32* null)
%49 = load i8*, i8** %2
ret i8* %49
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"Receive Error:\00"
@.str.2 = [12 x i8] c"Send error:\00"
@str = [25 x i8] c"Running a new thread now\00"
define noalias i8* @newSock(i8* nocapture %0) {
%2 = alloca [512 x i8]
%3 = alloca [1536 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1536 x i8], [1536 x i8]* %3, i64 0, i64 0
%6 = bitcast i8* %0 to i32*
%7 = load i32, i32* %6
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%9 = call i32 @recv(i32 %7, i8* %4, i32 512, i32 0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %31, label %11
11: ; preds = %1, %26
%12 = phi i32 [ %29, %26 ], [ %9, %1 ]
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = call i32 @strncat(i8* %5, i8* %4, i32 512)
%19 = call i32 @strncat(i8* %5, i8* %4, i32 512)
%20 = call i32 @strncat(i8* %5, i8* %4, i32 512)
%21 = call i64 @send(i32 %7, i8* %5, i32 1536, i32 0)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = call i32 @memset(i8* %5, i32 0, i32 1536)
%28 = call i32 @memset(i8* %4, i32 0, i32 512)
%29 = call i32 @recv(i32 %7, i8* %4, i32 512, i32 0)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %11
31: ; preds = %26, %1
%32 = call i32 @close(i32 %7)
%33 = call i32 @pthread_exit(i32* null)
ret i8* undef
}