#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*/ line;

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ openConn(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sendCmd(int, char *, int);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ waitRsp(int, char *, int);
void doProcessing() {
  int fd;
  int len;
  char line[2048];
  openConn(&fd);
  while (!feof(stdin)) {
    if (fgets(line, sizeof(line) - 1, stdin) == NULL)
      break;
    len = strlen(line);
    sendCmd(fd, line, len);
    waitRsp(fd, line, sizeof(line));
    printf("imdiag: %s", line);
  }
}


x86 assembly (clang, -O0):
<doProcessing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
lea    -0x4(%rbp),%rdi
call   1080 <openConn@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a7 <doProcessing+0x37>
jmp    121d <doProcessing+0xad>
lea    -0x810(%rbp),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
mov    $0x7ff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11d0 <doProcessing+0x60>
jmp    121d <doProcessing+0xad>
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <sendCmd@plt>
mov    -0x4(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x800,%edx
call   1090 <waitRsp@plt>
lea    -0x810(%rbp),%rsi
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
jmp    1184 <doProcessing+0x14>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doProcessing>:
push   %r15
push   %r14
push   %rbx
sub    $0x810,%rsp
lea    0xc(%rsp),%rdi
call   1080 <openConn@plt>
mov    0x2e5b(%rip),%r15
mov    (%r15),%edi
call   1070 <feof@plt>
test   %eax,%eax
jne    1203 <doProcessing+0x93>
lea    0x10(%rsp),%rbx
lea    0xe5b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x7ff,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1203 <doProcessing+0x93>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <sendCmd@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1090 <waitRsp@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    (%r15),%edi
call   1070 <feof@plt>
test   %eax,%eax
je     11b0 <doProcessing+0x40>
add    $0x810,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [11 x i8] c"imdiag: %s\00"
define void @doProcessing() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2048 x i8]
%4 = call i32 @openConn(i32* %1)
br label %5
5: ; preds = %16, %0
%6 = load i32, i32* @stdin
%7 = call i32 @feof(i32 %6)
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %28
10: ; preds = %5
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32* @fgets(i8* %11, i32 2047, i32 %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
br label %28
16: ; preds = %10
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %2
%19 = load i32, i32* %1
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* %2
%22 = call i32 @sendCmd(i32 %19, i8* %20, i32 %21)
%23 = load i32, i32* %1
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%25 = call i32 @waitRsp(i32 %23, i8* %24, i32 2048)
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %5
28: ; preds = %15, %5
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [11 x i8] c"imdiag: %s\00"
define void @doProcessing() {
%1 = alloca i32
%2 = alloca [2048 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%5 = call i32 @openConn(i32* %1)
%6 = load i32, i32* @stdin
%7 = call i32 @feof(i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %0, %13
%10 = load i32, i32* @stdin
%11 = call i32* @fgets(i8* %4, i32 2047, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %23, label %13
13: ; preds = %9
%14 = call i32 @strlen(i8* %4)
%15 = load i32, i32* %1
%16 = call i32 @sendCmd(i32 %15, i8* %4, i32 %14)
%17 = load i32, i32* %1
%18 = call i32 @waitRsp(i32 %17, i8* %4, i32 2048)
%19 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %4)
%20 = load i32, i32* @stdin
%21 = call i32 @feof(i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %9, label %23
23: ; preds = %13, %9, %0
ret void
}