#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__ pid_t;

/* Variables and functions */
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
scalar_t__ pipe(int *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int n;
  int fd[2];
  pid_t pid;
  char line[256];
  if (pipe(fd) < 0) {
    do {
      if (1 <= 4) {
        fprintf(stderr,
                "%s %d: "
                "pipe error",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/"
                "master/pipe/main.c",
                17);
      }
    } while (0);
    exit(-1);
  }
  if ((pid = fork()) < 0) {
    do {
      if (1 <= 4) {
        fprintf(stderr,
                "%s %d: "
                "fork error",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/"
                "master/pipe/main.c",
                22);
      }
    } while (0);
    exit(-1);
  } else if (pid > 0) {
    close(fd[0]);
    write(fd[1], "hello pipe\n", 12);
  } else {
    close(fd[1]);
    n = read(fd[0], line, 256);
    write(STDOUT_FILENO, line, n);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
jge    11c5 <main+0x55>
jmp    119a <main+0x2a>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
lea    0xe61(%rip),%rdx
mov    $0x11,%ecx
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    120a <main+0x9a>
jmp    11df <main+0x6f>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
lea    0xe1c(%rip),%rdx
mov    $0x16,%ecx
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jle    1236 <main+0xc6>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
lea    0xe86(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
jmp    126d <main+0xfd>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <write@plt>
jmp    1272 <main+0x102>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x110,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
test   %rax,%rax
jns    11a5 <main+0x35>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
lea    0xe74(%rip),%rdx
mov    $0x11,%ecx
jmp    11cd <main+0x5d>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jns    11dc <main+0x6c>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xeda(%rip),%rsi
lea    0xe4a(%rip),%rdx
mov    $0x16,%ecx
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jne    120d <main+0x9d>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    0x2dec(%rip),%rcx
mov    (%rcx),%edi
mov    %rbx,%rsi
mov    %eax,%edx
jmp    1226 <main+0xb6>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
lea    0xe8c(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"%s %d: pipe error\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/pipe/main.c\00"
@.str.2 = [18 x i8] c"%s %d: fork error\00"
@.str.3 = [12 x i8] c"hello pipe\0A\00"
@STDOUT_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca i64
%5 = alloca [256 x i8]
store i32 0, i32* %1
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%7 = call i64 @pipe(i32* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
br label %10
10: ; preds = %9
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 17)
br label %13
13: ; preds = %10
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
%16 = call i64 (...) @fork()
store i64 %16, i64* %4
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15
br label %19
19: ; preds = %18
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 22)
br label %22
22: ; preds = %19
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %15
%25 = load i64, i64* %4
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @write(i32 %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 12)
br label %46
34: ; preds = %24
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 256)
store i32 %41, i32* %2
%42 = load i32, i32* @STDOUT_FILENO
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%44 = load i32, i32* %2
%45 = call i32 @write(i32 %42, i8* %43, i32 %44)
br label %46
46: ; preds = %34, %27
br label %47
47: ; preds = %46
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"%s %d: pipe error\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/pipe/main.c\00"
@.str.2 = [18 x i8] c"%s %d: fork error\00"
@.str.3 = [12 x i8] c"hello pipe\0A\00"
@STDOUT_FILENO = global i32 0
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [256 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 17)
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = call i64 (...) @fork()
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 22)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %12
%20 = icmp eq i64 %13, 0
br i1 %20, label %27, label %21
21: ; preds = %19
%22 = load i32, i32* %5
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @write(i32 %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 12)
br label %35
27: ; preds = %19
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = load i32, i32* %5
%32 = call i32 @read(i32 %31, i8* %4, i32 256)
%33 = load i32, i32* @STDOUT_FILENO
%34 = call i32 @write(i32 %33, i8* %4, i32 %32)
br label %35
35: ; preds = %21, %27
%36 = call i32 @exit(i32 0)
unreachable
}