void output(int fd) {
  int r;
  char buf[1024];
  while ((r = read(fd, buf, sizeof(buf) - 1))) {
    if (!(r > 0)) {
      do {
        char message[1024];
        snprintf(message, sizeof(message), "$failure @%s() (%s:%u)", __func__,
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/redcap97/cyanurus/refs/"
                 "heads/master/src/test-user/unistd_pipe.c",
                 38);
        puts("\n"
             "--a94e2gfwdd--");
        puts(message);
        puts("$shudown");
        while (1)
          ;
      } while (0);
      ;
    };
    buf[r] = '\0';
    printf("%s", buf);
  }
}


x86 assembly (clang, -O0):
<output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
mov    $0x0,%al
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     1202 <output+0xc2>
cmpl   $0x0,-0x8(%rbp)
jg     11dc <output+0x9c>
jmp    117f <output+0x3f>
lea    -0x810(%rbp),%rdi
mov    $0x400,%esi
lea    0xe6e(%rip),%rdx
lea    0xe7e(%rip),%rcx
lea    0xe7e(%rip),%r8
mov    $0x26,%r9d
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    0xf04(%rip),%rdi
mov    $0x0,%al
call   1030 <puts@plt>
lea    -0x810(%rbp),%rdi
mov    $0x0,%al
call   1030 <puts@plt>
lea    0xef8(%rip),%rdi
mov    $0x0,%al
call   1030 <puts@plt>
jmp    11d7 <output+0x97>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    114e <output+0xe>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %edi,%ebp
mov    %rsp,%rsi
mov    $0x3ff,%edx
xor    %eax,%eax
call   1060 <read@plt>
test   %eax,%eax
je     119c <output+0x5c>
lea    0xf6a(%rip),%r14
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
jle    11a8 <output+0x68>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3ff,%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <read@plt>
test   %eax,%eax
jne    1170 <output+0x30>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe51(%rip),%rdx
lea    0xe61(%rip),%rcx
lea    0xe61(%rip),%r8
lea    0x400(%rsp),%rbx
mov    $0x400,%esi
mov    %rbx,%rdi
mov    $0x26,%r9d
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0xed7(%rip),%rdi
xor    %eax,%eax
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <puts@plt>
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1030 <puts@plt>
jmp    1200 <output+0xc0>

LLVM IR (-O0):
@.str = [23 x i8] c"$failure @%s() (%s:%u)\00"
@__func__.output = [7 x i8] c"output\00"
@.str.1 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/redcap97/cyanurus/refs/heads/master/src/test-user/unistd_pipe.c\00"
@.str.2 = [16 x i8] c"\0A--a94e2gfwdd--\00"
@.str.3 = [9 x i8] c"$shudown\00"
@.str.4 = [3 x i8] c"%s\00"
define void @output(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
store i32 %0, i32* %2
br label %6
6: ; preds = %24, %1
%7 = load i32, i32* %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %7, i8* %8, i64 1023)
store i32 %9, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %6
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %11
br label %15
15: ; preds = %14
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %16, i64 1024, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__func__.output, i64 0, i64 0), i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.1, i64 0, i64 0), i32 38)
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* %19)
%21 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %15, %22
br label %22
23: ; No predecessors!
br label %24
24: ; preds = %23, %11
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %26
store i8 0, i8* %27
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %28)
br label %6
30: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"$failure @%s() (%s:%u)\00"
@__func__.output = [7 x i8] c"output\00"
@.str.1 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/redcap97/cyanurus/refs/heads/master/src/test-user/unistd_pipe.c\00"
@.str.2 = [16 x i8] c"\0A--a94e2gfwdd--\00"
@.str.3 = [9 x i8] c"$shudown\00"
@.str.4 = [3 x i8] c"%s\00"
define void @output(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %0, i8* %4, i64 1023)
%6 = icmp eq i32 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %1, %17
%8 = phi i32 [ %21, %17 ], [ %5, %1 ]
%9 = icmp sgt i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %11, i64 1024, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__func__.output, i64 0, i64 0), i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.1, i64 0, i64 0), i32 38)
%13 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* %11)
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %16, %10
br label %16
17: ; preds = %7
%18 = zext i32 %8 to i64
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%21 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %0, i8* %4, i64 1023)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %7
23: ; preds = %17, %1
ret void
}