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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memcpy(char *, void *, size_t);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
char *strchr(char *, char);
int tcp_client(char *, char *);
void connection_handler(int udpsock, void *data, size_t size) {
  int sock;
  char *ptr, buffer[256];
  ssize_t len;
  memcpy(buffer, data, size);
  ptr = strchr(buffer, ':');
  *ptr++ = '\0';
  sock = tcp_client(buffer, ptr);
  while ((len = recv(udpsock, buffer, sizeof(buffer), 0)) > 0) {
    send(sock, buffer, len, 0);
  }
  close(sock);
  close(udpsock);
}


x86 assembly (clang, -O0):
<connection_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <memcpy@plt>
lea    -0x130(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <tcp_client@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x134(%rbp)
cmp    $0x0,%eax
jle    1205 <connection_handler+0xa5>
mov    -0x1c(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    -0x134(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
jmp    11c4 <connection_handler+0x64>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connection_handler>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %edi,%r14d
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <memcpy@plt>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
movb   $0x0,(%rax)
lea    0x1(%rax),%rsi
mov    %rbx,%rdi
call   1080 <tcp_client@plt>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    11d4 <connection_handler+0x74>
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jg     11b0 <connection_handler+0x50>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14d,%edi
call   1060 <close@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @connection_handler(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call i32 @memcpy(i8* %11, i8* %12, i64 %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%16 = call i8* @strchr(i8* %15, i8 signext 58)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %8
store i8 0, i8* %17
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%20 = load i8*, i8** %8
%21 = call i32 @tcp_client(i8* %19, i8* %20)
store i32 %21, i32* %7
br label %22
22: ; preds = %27, %3
%23 = load i32, i32* %4
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = call i32 @recv(i32 %23, i8* %24, i32 256, i32 0)
store i32 %25, i32* %10
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* %7
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%30 = load i32, i32* %10
%31 = call i32 @send(i32 %28, i8* %29, i32 %30, i32 0)
br label %22
32: ; preds = %22
%33 = load i32, i32* %7
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %4
%36 = call i32 @close(i32 %35)
ret void
}

LLVM IR (-O2):
define void @connection_handler(i32 %0, i8* %1, i64 %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @memcpy(i8* %5, i8* %1, i64 %2)
%7 = call i8* @strchr(i8* %5, i8 signext 58)
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8 0, i8* %7
%9 = call i32 @tcp_client(i8* %5, i8* %8)
%10 = call i32 @recv(i32 %0, i8* %5, i32 256, i32 0)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %3, %12
%13 = phi i32 [ %15, %12 ], [ %10, %3 ]
%14 = call i32 @send(i32 %9, i8* %5, i32 %13, i32 0)
%15 = call i32 @recv(i32 %0, i8* %5, i32 256, i32 0)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %12, label %17
17: ; preds = %12, %3
%18 = call i32 @close(i32 %9)
%19 = call i32 @close(i32 %0)
ret void
}