#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 */
struct timespec {
  int tv_sec;
  scalar_t__ tv_nsec;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncmp(char *, char *, int);
int handle_conn(int sock) {
  char input[65536 + 1];
  ssize_t len;
  struct timespec ts;
  read(STDIN_FILENO, input, 4);
  input[4] = '\0';
  fprintf(stderr, "dummy-LTP cmd: %s\n", input);
  read(STDIN_FILENO, input, 128);
  input[128] = '\0';
  fprintf(stderr, "dummy-LTP listens to url: %s\n", input);
  ts.tv_sec = 3;
  ts.tv_nsec = 0;
  nanosleep(&ts, NULL);
  while (1) {
    len = read(STDIN_FILENO, input, 65536 + 1);
    if (len < 0) {
      perror("tp/dummy/listen: read");
      return 1;
    }
    if (len > 65536) {
      fprintf(stderr, "Packet too big (%lu)!\n", len);
      continue;
    }
    input[len] = '\0';
    fprintf(stderr, "dummy-LTP received command: %s (until first \\0)\n",
            input);
    if (!strncmp(input, "1002", 4)) {
      fprintf(stderr, "dummy/c: Time to say goodbye...\n");
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<handle_conn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
movb   $0x0,-0x1000c(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rdx
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rsi
mov    $0x80,%edx
call   1050 <read@plt>
movb   $0x0,-0xff90(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x3,-0x10028(%rbp)
movq   $0x0,-0x10020(%rbp)
lea    -0x10028(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rsi
mov    $0x10001,%edx
call   1050 <read@plt>
mov    %eax,-0x10014(%rbp)
cmpl   $0x0,-0x10014(%rbp)
jge    1246 <handle_conn+0xf6>
lea    0xdfc(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ee <handle_conn+0x19e>
cmpl   $0x10000,-0x10014(%rbp)
jle    1278 <handle_conn+0x128>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    -0x10014(%rbp),%edx
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1201 <handle_conn+0xb1>
movslq -0x10014(%rbp),%rax
movb   $0x0,-0x10010(%rbp,%rax,1)
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rdx
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x10010(%rbp),%rdi
lea    0xddc(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12e9 <handle_conn+0x199>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ee <handle_conn+0x19e>
jmp    1201 <handle_conn+0xb1>
mov    -0x4(%rbp),%eax
add    $0x10030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_conn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10018,%rsp
mov    0x2e70(%rip),%r13
mov    0x0(%r13),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
movb   $0x0,0x14(%rsp)
mov    0x2e56(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1050 <read@plt>
movb   $0x0,0x90(%rsp)
mov    0x0(%rbp),%edi
lea    0xe52(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
movl   $0x3,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
mov    $0x10001,%edx
call   1050 <read@plt>
test   %eax,%eax
js     129d <handle_conn+0x14d>
lea    0xe42(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe4d(%rip),%r15
lea    0xe77(%rip),%r12
jmp    1244 <handle_conn+0xf4>
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
mov    $0x10001,%edx
call   1050 <read@plt>
test   %eax,%eax
js     129d <handle_conn+0x14d>
cmp    $0x10001,%eax
jae    1220 <handle_conn+0xd0>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    0x0(%rbp),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    122f <handle_conn+0xdf>
mov    0x0(%rbp),%edi
lea    0xe14(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%eax
add    $0x10018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%ebx
jmp    1289 <handle_conn+0x139>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"dummy-LTP cmd: %s\0A\00"
@.str.1 = [30 x i8] c"dummy-LTP listens to url: %s\0A\00"
@.str.2 = [22 x i8] c"tp/dummy/listen: read\00"
@.str.3 = [23 x i8] c"Packet too big (%lu)!\0A\00"
@.str.4 = [49 x i8] c"dummy-LTP received command: %s (until first \\0)\0A\00"
@.str.5 = [5 x i8] c"1002\00"
@.str.6 = [33 x i8] c"dummy/c: Time to say goodbye...\0A\00"
define i32 @handle_conn(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [65537 x i8]
%5 = alloca i32
%6 = alloca %struct.timespec
store i32 %0, i32* %3
%7 = load i32, i32* @STDIN_FILENO
%8 = getelementptr inbounds [65537 x i8], [65537 x i8]* %4, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 4)
%10 = getelementptr inbounds [65537 x i8], [65537 x i8]* %4, i64 0, i64 4
store i8 0, i8* %10
%11 = load i32, i32* @stderr
%12 = getelementptr inbounds [65537 x i8], [65537 x i8]* %4, i64 0, i64 0
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @STDIN_FILENO
%15 = getelementptr inbounds [65537 x i8], [65537 x i8]* %4, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 128)
%17 = getelementptr inbounds [65537 x i8], [65537 x i8]* %4, i64 0, i64 128
store i8 0, i8* %17
%18 = load i32, i32* @stderr
%19 = getelementptr inbounds [65537 x i8], [65537 x i8]* %4, i64 0, i64 0
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
store i32 3, i32* %21
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
store i64 0, i64* %22
%23 = call i32 @nanosleep(%struct.timespec* %6, i32* null)
br label %24
24: ; preds = %1, %35, %52
%25 = load i32, i32* @STDIN_FILENO
%26 = getelementptr inbounds [65537 x i8], [65537 x i8]* %4, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 65537)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %53
32: ; preds = %24
%33 = load i32, i32* %5
%34 = icmp sgt i32 %33, 65536
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = load i32, i32* %5
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %24
39: ; preds = %32
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [65537 x i8], [65537 x i8]* %4, i64 0, i64 %41
store i8 0, i8* %42
%43 = load i32, i32* @stderr
%44 = getelementptr inbounds [65537 x i8], [65537 x i8]* %4, i64 0, i64 0
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = getelementptr inbounds [65537 x i8], [65537 x i8]* %4, i64 0, i64 0
%47 = call i32 @strncmp(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%48 = icmp ne i32 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %39
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %2
br label %53
52: ; preds = %39
br label %24
53: ; preds = %49, %30
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"dummy-LTP cmd: %s\0A\00"
@.str.1 = [30 x i8] c"dummy-LTP listens to url: %s\0A\00"
@.str.2 = [22 x i8] c"tp/dummy/listen: read\00"
@.str.3 = [23 x i8] c"Packet too big (%lu)!\0A\00"
@.str.4 = [49 x i8] c"dummy-LTP received command: %s (until first \\0)\0A\00"
@.str.5 = [5 x i8] c"1002\00"
@.str.6 = [33 x i8] c"dummy/c: Time to say goodbye...\0A\00"
define i32 @handle_conn(i32 %0) {
%2 = alloca [65537 x i8]
%3 = alloca %struct.timespec
%4 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 0
%5 = bitcast %struct.timespec* %3 to i8*
%6 = load i32, i32* @STDIN_FILENO
%7 = call i32 @read(i32 %6, i8* %4, i32 4)
%8 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 4
store i8 0, i8* %8
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %4)
%11 = load i32, i32* @STDIN_FILENO
%12 = call i32 @read(i32 %11, i8* %4, i32 128)
%13 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 128
store i8 0, i8* %13
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i32 3, i32* %16
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i64 0, i64* %17
%18 = call i32 @nanosleep(%struct.timespec* %3, i32* null)
%19 = load i32, i32* @STDIN_FILENO
%20 = call i32 @read(i32 %19, i8* %4, i32 65537)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %30, %1
%23 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %44
24: ; preds = %1, %30
%25 = phi i32 [ %32, %30 ], [ %20, %1 ]
%26 = icmp ugt i32 %25, 65536
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %30
30: ; preds = %27, %34
%31 = load i32, i32* @STDIN_FILENO
%32 = call i32 @read(i32 %31, i8* %4, i32 65537)
%33 = icmp slt i32 %32, 0
br i1 %33, label %22, label %24
34: ; preds = %24
%35 = zext i32 %25 to i64
%36 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 %35
store i8 0, i8* %36
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%39 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %30
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %41, %22
%45 = phi i32 [ 1, %22 ], [ 0, %41 ]
ret i32 %45
}