#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
char *calloc(int, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ read(int /*<<< orphan*/, char *, int);
scalar_t__ sanitize_crlf(char *, scalar_t__);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
scalar_t__ write(int, char *, int);
void echo() {
  bool got_eof = false;
  char *buffer = calloc(1, 1);
  do {
    if (errno) {
      fprintf(stderr, "Internal Error: %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
  } while (0);
  while (!got_eof) {
    ssize_t chars_read = read(0, buffer, 1);
    do {
      if (errno) {
        fprintf(stderr, "Internal Error: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
      }
    } while (0);
    chars_read = sanitize_crlf(buffer, chars_read);
    if (chars_read > 0) {
      for (int i = 0; i < chars_read; ++i) {
        if (buffer[i] != 0x4) {
          ssize_t bytes_written = write(1, buffer + i, 1);
          if (bytes_written <= 0) {
            do {
              if (errno) {
                fprintf(stderr, "Internal Error: %s\n", strerror(errno));
                exit(EXIT_FAILURE);
              }
            } while (0);
          }
        } else {
          got_eof = true;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%esi
mov    %esi,%edi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e42(%rip),%rax
cmpq   $0x0,(%rax)
je     11db <echo+0x6b>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe38(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11e0 <echo+0x70>
jmp    11e5 <echo+0x75>
cmpl   $0x0,-0x4(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11fb <echo+0x8b>
jmp    1350 <echo+0x1e0>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %rax,-0x18(%rbp)
mov    0x2dc2(%rip),%rax
cmpq   $0x0,(%rax)
je     125b <echo+0xeb>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2da5(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xdb8(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1260 <echo+0xf0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <sanitize_crlf@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    134b <echo+0x1db>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1346 <echo+0x1d6>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x4,%eax
je     132c <echo+0x1bc>
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1030 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jg     1327 <echo+0x1b7>
jmp    12d1 <echo+0x161>
mov    0x2d00(%rip),%rax
cmpq   $0x0,(%rax)
je     131d <echo+0x1ad>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2ce3(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xcf6(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1322 <echo+0x1b2>
jmp    1327 <echo+0x1b7>
jmp    1333 <echo+0x1c3>
movl   $0x1,-0x4(%rbp)
jmp    1338 <echo+0x1c8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1283 <echo+0x113>
jmp    134b <echo+0x1db>
jmp    11e5 <echo+0x75>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    0x2e4a(%rip),%r12
mov    (%r12),%rdi
test   %rdi,%rdi
jne    121a <echo+0xaa>
mov    %rax,%r14
jmp    11aa <echo+0x3a>
xor    %eax,%eax
test   %eax,%eax
jne    1247 <echo+0xd7>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    (%r12),%rdi
test   %rdi,%rdi
jne    121a <echo+0xaa>
mov    %r14,%rdi
mov    %rax,%rsi
call   1090 <sanitize_crlf@plt>
test   %rax,%rax
jle    11a0 <echo+0x30>
mov    %rax,%r15
xor    %ebp,%ebp
mov    %r14,%rbx
jmp    11ee <echo+0x7e>
nopl   0x0(%rax)
mov    %ebp,%eax
add    $0x1,%rbx
mov    %eax,%ebp
add    $0xffffffffffffffff,%r15
je     11a2 <echo+0x32>
mov    $0x1,%eax
cmpb   $0x4,(%rbx)
je     11e2 <echo+0x72>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
test   %rax,%rax
jg     11e0 <echo+0x70>
mov    (%r12),%rdi
mov    %ebp,%eax
test   %rdi,%rdi
je     11e2 <echo+0x72>
mov    0x2dbf(%rip),%rax
mov    (%rax),%ebx
call   1080 <strerror@plt>
lea    0xdd1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"Internal Error: %s\0A\00"
@EXIT_FAILURE = global i32 0
define void @echo() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
store i32 0, i32* %1
%6 = call i8* @calloc(i32 1, i32 1)
store i8* %6, i8** %2
br label %7
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = load i64, i64* @errno
%13 = call i8* @strerror(i64 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %7
br label %18
18: ; preds = %17
br label %19
19: ; preds = %85, %18
%20 = load i32, i32* %1
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %86
23: ; preds = %19
%24 = load i8*, i8** %2
%25 = call i64 @read(i32 0, i8* %24, i32 1)
store i64 %25, i64* %3
br label %26
26: ; preds = %23
%27 = load i64, i64* @errno
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = load i64, i64* @errno
%32 = call i8* @strerror(i64 %31)
%33 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %26
br label %37
37: ; preds = %36
%38 = load i8*, i8** %2
%39 = load i64, i64* %3
%40 = call i64 @sanitize_crlf(i8* %38, i64 %39)
store i64 %40, i64* %3
%41 = load i64, i64* %3
%42 = icmp sgt i64 %41, 0
br i1 %42, label %43, label %85
43: ; preds = %37
store i32 0, i32* %4
br label %44
44: ; preds = %81, %43
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = load i64, i64* %3
%48 = icmp slt i64 %46, %47
br i1 %48, label %49, label %84
49: ; preds = %44
%50 = load i8*, i8** %2
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 4
br i1 %56, label %57, label %79
57: ; preds = %49
%58 = load i8*, i8** %2
%59 = load i32, i32* %4
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = call i64 @write(i32 1, i8* %61, i32 1)
store i64 %62, i64* %5
%63 = load i64, i64* %5
%64 = icmp sle i64 %63, 0
br i1 %64, label %65, label %78
65: ; preds = %57
br label %66
66: ; preds = %65
%67 = load i64, i64* @errno
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %66
%70 = load i32, i32* @stderr
%71 = load i64, i64* @errno
%72 = call i8* @strerror(i64 %71)
%73 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %72)
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %66
br label %77
77: ; preds = %76
br label %78
78: ; preds = %77, %57
br label %80
79: ; preds = %49
store i32 1, i32* %1
br label %80
80: ; preds = %79, %78
br label %81
81: ; preds = %80
%82 = load i32, i32* %4
%83 = add nsw i32 %82, 1
store i32 %83, i32* %4
br label %44
84: ; preds = %44
br label %85
85: ; preds = %84, %37
br label %19
86: ; preds = %19
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"Internal Error: %s\0A\00"
@EXIT_FAILURE = global i32 0
define void @echo() {
%1 = tail call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
%2 = load i64, i64* @errno
%3 = icmp eq i64 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i8* @strerror(i64 %2)
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0, %45
%11 = tail call i64 @read(i32 0, i8* %1, i32 1)
%12 = load i64, i64* @errno
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i8* @strerror(i64 %12)
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = tail call i64 @sanitize_crlf(i8* %1, i64 %11)
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %45
23: ; preds = %20, %41
%24 = phi i64 [ %43, %41 ], [ 0, %20 ]
%25 = phi i32 [ %42, %41 ], [ 0, %20 ]
%26 = getelementptr inbounds i8, i8* %1, i64 %24
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 4
br i1 %28, label %41, label %29
29: ; preds = %23
%30 = tail call i64 @write(i32 1, i8* %26, i32 1)
%31 = icmp slt i64 %30, 1
%32 = load i64, i64* @errno
%33 = icmp ne i64 %32, 0
%34 = select i1 %31, i1 %33, i1 false
br i1 %34, label %35, label %41
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = tail call i8* @strerror(i64 %32)
%38 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %23, %29
%42 = phi i32 [ %25, %29 ], [ 1, %23 ]
%43 = add nuw nsw i64 %24, 1
%44 = icmp eq i64 %43, %21
br i1 %44, label %45, label %23
45: ; preds = %41, %20
%46 = phi i32 [ 0, %20 ], [ %42, %41 ]
%47 = icmp eq i32 %46, 0
br i1 %47, label %10, label %48
48: ; preds = %45
ret void
}