#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*/ close(int);
int fork();
int /*<<< orphan*/ pipe(int *);
scalar_t__ read(int, char **, int);
int /*<<< orphan*/ write(int, ...);
int main(int argc, char **argv) {
  int pd[2];
  pipe(pd);
  int pid = fork();
  char buf[32];
  if (pid == 0) {
    close(pd[1]);
    while (read(pd[0], &buf, 32) > 0 && buf != 0) {
      write(1, &buf, 32);
    }
    close(pd[0]);
  } else {
    close(pd[0]);
    write(pd[1], "abc ola ola\n", 32);
    close(pd[1]);
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11f3 <main+0xa3>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1060 <read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x41(%rbp)
jle    11bc <main+0x6c>
lea    -0x40(%rbp),%rax
cmp    $0x0,%rax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11cc <main+0x7c>
jmp    11e6 <main+0x96>
mov    $0x1,%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    118b <main+0x3b>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
jmp    1219 <main+0xc9>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
lea    0xdfb(%rip),%rsi
mov    $0x20,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1190 <main+0x40>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
lea    0xe82(%rip),%rsi
mov    $0x20,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    0xc(%rsp),%edi
jmp    11ee <main+0x9e>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    11ea <main+0x9a>
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1060 <read@plt>
test   %rax,%rax
jg     11c0 <main+0x70>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"abc ola ola\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca [32 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = call i32 (...) @fork()
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %2
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @close(i32 %16)
br label %18
18: ; preds = %29, %14
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%20 = load i32, i32* %19
%21 = bitcast [32 x i8]* %8 to i8**
%22 = call i64 @read(i32 %20, i8** %21, i32 32)
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%26 = icmp ne i8* %25, null
br label %27
27: ; preds = %24, %18
%28 = phi i1 [ false, %18 ], [ %26, %24 ]
br i1 %28, label %29, label %31
29: ; preds = %27
%30 = call i32 (i32, ...) @write(i32 1, [32 x i8]* %8, i32 32)
br label %18
31: ; preds = %27
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
br label %45
35: ; preds = %2
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 (i32, ...) @write(i32 %40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 32)
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%43 = load i32, i32* %42
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %35, %31
ret i32 1
}

LLVM IR (-O2):
@.str = [13 x i8] c"abc ola ola\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [32 x i8]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = call i32 (...) @fork()
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%10 = icmp eq i32 %8, 0
br i1 %10, label %11, label %26
11: ; preds = %2
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = bitcast [32 x i8]* %4 to i8**
%16 = load i32, i32* %6
%17 = call i64 @read(i32 %16, i8** %15, i32 32)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %11, %19
%20 = call i32 (i32, ...) @write(i32 1, [32 x i8]* %4, i32 32)
%21 = load i32, i32* %6
%22 = call i64 @read(i32 %21, i8** %15, i32 32)
%23 = icmp sgt i64 %22, 0
br i1 %23, label %19, label %24
24: ; preds = %19, %11
%25 = load i32, i32* %6
br label %33
26: ; preds = %2
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 (i32, ...) @write(i32 %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 32)
%32 = load i32, i32* %29
br label %33
33: ; preds = %26, %24
%34 = phi i32 [ %32, %26 ], [ %25, %24 ]
%35 = call i32 @close(i32 %34)
ret i32 1
}