#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*/ STDIN_FILENO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int main() {
  char input[65536 + 1];
  char *eos;
  int len;
  read(STDIN_FILENO, input, 4);
  input[4] = '\0';
  fprintf(stderr, "dummy-TP cmd: %s\n", input);
  read(STDIN_FILENO, input, 128);
  input[128] = '\0';
  fprintf(stderr, "dummy-TP url: %s\n", input);
  len = read(STDIN_FILENO, input, 65536);
  input[len] = '\0';
  eos = strchr(input, '\n');
  if (!eos) {
    printf("2001");
    return 1;
  } else {
    *eos = '\0';
  }
  fprintf(stderr, "dummy-TP size: %s\n", input);
  fprintf(stderr, "dummy-TP packet: %s\n", eos + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10020,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
movb   $0x0,-0x1000c(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rsi
mov    $0x80,%edx
call   1050 <read@plt>
movb   $0x0,-0xff90(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rdx
lea    0xe4b(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rsi
mov    $0x10000,%edx
call   1050 <read@plt>
mov    %eax,-0x1001c(%rbp)
movslq -0x1001c(%rbp),%rax
movb   $0x0,-0x10010(%rbp,%rax,1)
lea    -0x10010(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10018(%rbp)
cmpq   $0x0,-0x10018(%rbp)
jne    1239 <main+0xf9>
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1286 <main+0x146>
mov    -0x10018(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rdx
lea    0xdcf(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    -0x10018(%rbp),%rdx
add    $0x1,%rdx
lea    0xdc2(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10010,%rsp
mov    0x2e85(%rip),%r15
mov    (%r15),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
movb   $0x0,0x4(%rsp)
mov    0x2e6e(%rip),%r14
mov    (%r14),%edi
lea    0xe84(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1050 <read@plt>
movb   $0x0,0x80(%rsp)
mov    (%r14),%edi
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x10000,%edx
call   1050 <read@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1208 <main+0xc8>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    (%r14),%edi
lea    0xe43(%rip),%rsi
mov    %rsp,%rdx
call   1060 <fprintf@plt>
mov    (%r14),%edi
add    $0x1,%rbx
lea    0xe40(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
xor    %eax,%eax
jmp    1219 <main+0xd9>
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x10010,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"dummy-TP cmd: %s\0A\00"
@.str.1 = [18 x i8] c"dummy-TP url: %s\0A\00"
@.str.2 = [5 x i8] c"2001\00"
@.str.3 = [19 x i8] c"dummy-TP size: %s\0A\00"
@.str.4 = [21 x i8] c"dummy-TP packet: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [65537 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @STDIN_FILENO
%6 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 0
%7 = call i32 @read(i32 %5, i8* %6, 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 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 0
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @STDIN_FILENO
%13 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 0
%14 = call i32 @read(i32 %12, i8* %13, i32 128)
%15 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 128
store i8 0, i8* %15
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 0
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @STDIN_FILENO
%20 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 65536)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 %23
store i8 0, i8* %24
%25 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 0
%26 = call i8* @strchr(i8* %25, i8 signext 10)
store i8* %26, i8** %3
%27 = load i8*, i8** %3
%28 = icmp ne i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %0
%30 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %41
31: ; preds = %0
%32 = load i8*, i8** %3
store i8 0, i8* %32
br label %33
33: ; preds = %31
%34 = load i32, i32* @stderr
%35 = getelementptr inbounds [65537 x i8], [65537 x i8]* %2, i64 0, i64 0
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %39)
store i32 0, i32* %1
br label %41
41: ; preds = %33, %29
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"dummy-TP cmd: %s\0A\00"
@.str.1 = [18 x i8] c"dummy-TP url: %s\0A\00"
@.str.2 = [5 x i8] c"2001\00"
@.str.3 = [19 x i8] c"dummy-TP size: %s\0A\00"
@.str.4 = [21 x i8] c"dummy-TP packet: %s\0A\00"
define i32 @main() {
%1 = alloca [65537 x i8]
%2 = getelementptr inbounds [65537 x i8], [65537 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @read(i32 %3, i8* %2, i32 4)
%5 = getelementptr inbounds [65537 x i8], [65537 x i8]* %1, i64 0, i64 4
store i8 0, i8* %5
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = load i32, i32* @STDIN_FILENO
%9 = call i32 @read(i32 %8, i8* %2, i32 128)
%10 = getelementptr inbounds [65537 x i8], [65537 x i8]* %1, i64 0, i64 128
store i8 0, i8* %10
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%13 = load i32, i32* @STDIN_FILENO
%14 = call i32 @read(i32 %13, i8* %2, i32 65536)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [65537 x i8], [65537 x i8]* %1, i64 0, i64 %15
store i8 0, i8* %16
%17 = call i8* @strchr(i8* %2, i8 signext 10)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %27
21: ; preds = %0
store i8 0, i8* %17
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%24 = load i32, i32* @stderr
%25 = getelementptr inbounds i8, i8* %17, i64 1
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %21, %19
%28 = phi i32 [ 0, %21 ], [ 1, %19 ]
ret i32 %28
}