#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*/ PR_SET_PTRACER;
int /*<<< orphan*/ PR_SET_PTRACER_ANY;
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ prctl(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char *line = NULL;
  size_t cap = 0;
  prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
  while (getline(&line, &cap, stdin) != -1) {
    printf("ECHO: %s", line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
call   1040 <prctl@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     11a1 <main+0x71>
mov    -0x18(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
jmp    116d <main+0x3d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
call   1040 <prctl@plt>
mov    0x2e7d(%rip),%r12
mov    (%r12),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     11c1 <main+0x91>
lea    0xe76(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
jne    11a0 <main+0x70>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@PR_SET_PTRACER = global i32 0
@PR_SET_PTRACER_ANY = global i32 0
@stdin = global i32 0
@.str = [9 x i8] c"ECHO: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i64 0, i64* %7
%8 = load i32, i32* @PR_SET_PTRACER
%9 = load i32, i32* @PR_SET_PTRACER_ANY
%10 = call i32 @prctl(i32 %8, i32 %9)
br label %11
11: ; preds = %15, %2
%12 = load i32, i32* @stdin
%13 = call i32 @getline(i8** %6, i64* %7, i32 %12)
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %11
18: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@PR_SET_PTRACER = global i32 0
@PR_SET_PTRACER_ANY = global i32 0
@stdin = global i32 0
@.str = [9 x i8] c"ECHO: %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = load i32, i32* @PR_SET_PTRACER
%8 = load i32, i32* @PR_SET_PTRACER_ANY
%9 = tail call i32 @prctl(i32 %7, i32 %8)
%10 = load i32, i32* @stdin
%11 = call i32 @getline(i8** %3, i64* %4, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %19, label %13
13: ; preds = %2, %13
%14 = load i8*, i8** %3
%15 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @stdin
%17 = call i32 @getline(i8** %3, i64* %4, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %13
19: ; preds = %13, %2
ret i32 0
}