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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int read_protocol(char *, char *, int);
int redirect(char *, char *, int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
void process_line(const char *line) {
  char input[((2 * 2048) - 1) + 1], output[((2 * 2048) - 1) + 1],
      protocol[15 + 1], path[255 + 1];
  ssize_t size;
  if (strlen(line) > ((2 * 2048) - 1)) {
    fprintf(stderr, "line too long\n");
    goto out;
  }
  strcpy(input, line);
  while (1) {
    if (read_protocol(input, protocol, sizeof(protocol)) == -1) {
      fprintf(stderr, "cannot read protocol\n");
      goto out;
    }
    strcpy(path, "nb");
    strcpy(path + 2, protocol);
    size = redirect(path, input, strlen(input), output, sizeof(output));
    if (size == -1) {
      fputs(input, stdout);
      break;
    } else {
      output[size] = '\0';
      strcpy(input, output);
    }
  }
out:
  return;
}


x86 assembly (clang, -O0):
<process_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2140,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0xfff,%eax
jle    119d <process_line+0x3d>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12b5 <process_line+0x155>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x1010(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
mov    $0x10,%edx
call   1080 <read_protocol@plt>
cmp    $0xffffffff,%eax
jne    11e8 <process_line+0x88>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12b5 <process_line+0x155>
lea    -0x2120(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x2120(%rbp),%rdi
add    $0x2,%rdi
lea    -0x2020(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x2120(%rbp),%rax
mov    %rax,-0x2138(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x2130(%rbp)
lea    -0x1010(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2138(%rbp),%rdi
mov    -0x2130(%rbp),%rsi
mov    %eax,%edx
lea    -0x2010(%rbp),%rcx
mov    $0x1000,%r8d
call   1040 <redirect@plt>
mov    %eax,-0x2124(%rbp)
cmpl   $0xffffffff,-0x2124(%rbp)
jne    1289 <process_line+0x129>
lea    -0x1010(%rbp),%rdi
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
jmp    12b0 <process_line+0x150>
movslq -0x2124(%rbp),%rax
movb   $0x0,-0x2010(%rbp,%rax,1)
lea    -0x1010(%rbp),%rdi
lea    -0x2010(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11ad <process_line+0x4d>
jmp    12b5 <process_line+0x155>
add    $0x2140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2118,%rsp
mov    %rdi,%rbx
call   1050 <strlen@plt>
cmp    $0x1000,%eax
jl     11a6 <process_line+0x46>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
add    $0x2118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fprintf@plt>
lea    0x110(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    $0x10,%edx
call   1080 <read_protocol@plt>
cmp    $0xffffffff,%eax
je     1263 <process_line+0x103>
lea    0x12(%rsp),%r14
lea    0xe47(%rip),%r15
lea    0x10(%rsp),%r13
mov    %rsp,%r12
lea    0x110(%rsp),%rbx
lea    0x1110(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %rbp,%rcx
mov    $0x1000,%r8d
call   1040 <redirect@plt>
cmp    $0xffffffff,%eax
je     127a <process_line+0x11a>
cltq
movb   $0x0,0x1110(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x10,%edx
call   1080 <read_protocol@plt>
cmp    $0xffffffff,%eax
jne    1200 <process_line+0xa0>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xd9c(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1290 <process_line+0x130>
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
lea    0x110(%rsp),%rdi
call   1060 <fputs@plt>
add    $0x2118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"line too long\0A\00"
@.str.1 = [22 x i8] c"cannot read protocol\0A\00"
@.str.2 = [3 x i8] c"nb\00"
@stdout = global i32 0
define void @process_line(i8* %0) {
%2 = alloca i8*
%3 = alloca [4096 x i8]
%4 = alloca [4096 x i8]
%5 = alloca [16 x i8]
%6 = alloca [256 x i8]
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = icmp sgt i32 %9, 4095
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %54
14: ; preds = %1
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %15, i8* %16)
br label %18
18: ; preds = %14, %52
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%21 = call i32 @read_protocol(i8* %19, i8* %20, i32 16)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %54
26: ; preds = %18
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 2
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%38 = call i32 @redirect(i8* %33, i8* %34, i32 %36, i8* %37, i32 4096)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %45
41: ; preds = %26
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%43 = load i32, i32* @stdout
%44 = call i32 @fputs(i8* %42, i32 %43)
br label %53
45: ; preds = %26
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %47
store i8 0, i8* %48
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%51 = call i32 @strcpy(i8* %49, i8* %50)
br label %52
52: ; preds = %45
br label %18
53: ; preds = %41
br label %54
54: ; preds = %53, %23, %11
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"line too long\0A\00"
@.str.1 = [22 x i8] c"cannot read protocol\0A\00"
@.str.2 = [3 x i8] c"nb\00"
@stdout = global i32 0
define void @process_line(i8* %0) {
%2 = alloca [4096 x i8]
%3 = alloca [4096 x i8]
%4 = alloca [16 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = tail call i32 @strlen(i8* %0)
%11 = icmp sgt i32 %10, 4095
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %39
15: ; preds = %1
%16 = call i32 @strcpy(i8* %6, i8* %0)
%17 = call i32 @read_protocol(i8* %6, i8* %8, i32 16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 2
br label %24
21: ; preds = %33, %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %39
24: ; preds = %19, %33
%25 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @strcpy(i8* %20, i8* %8)
%27 = call i32 @strlen(i8* %6)
%28 = call i32 @redirect(i8* %9, i8* %6, i32 %27, i8* %7, i32 4096)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i32, i32* @stdout
%32 = call i32 @fputs(i8* %6, i32 %31)
br label %39
33: ; preds = %24
%34 = sext i32 %28 to i64
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %34
store i8 0, i8* %35
%36 = call i32 @strcpy(i8* %6, i8* %7)
%37 = call i32 @read_protocol(i8* %6, i8* %8, i32 16)
%38 = icmp eq i32 %37, -1
br i1 %38, label %21, label %24
39: ; preds = %30, %21, %12
ret void
}