#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 *);
int /*<<< orphan*/ 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]);
    read(pd[0], &buf, 32);
    close(pd[0]);
    write(1, &buf, 32);
  } else {
    close(pd[0]);
    write(pd[1], "abc\n", 32);
    close(pd[1]);
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    11be <main+0x6e>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1060 <read@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    11e4 <main+0x94>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
lea    0xe30(%rip),%rsi
mov    $0x20,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%eax
add    $0x40,%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     1195 <main+0x45>
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
call   1040 <close@plt>
jmp    11d1 <main+0x81>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x20,%edx
call   1060 <read@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"abc\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 %26
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)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%19 = load i32, i32* %18
%20 = bitcast [32 x i8]* %8 to i8**
%21 = call i32 @read(i32 %19, i8** %20, i32 32)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = call i32 (i32, ...) @write(i32 1, [32 x i8]* %8, i32 32)
br label %36
26: ; preds = %2
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 (i32, ...) @write(i32 %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 32)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%34 = load i32, i32* %33
%35 = call i32 @close(i32 %34)
br label %36
36: ; preds = %26, %14
ret i32 1
}

LLVM IR (-O2):
@.str = [5 x i8] c"abc\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 %21
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 = load i32, i32* %6
%16 = bitcast [32 x i8]* %4 to i8**
%17 = call i32 @read(i32 %15, i8** %16, i32 32)
%18 = load i32, i32* %6
%19 = call i32 @close(i32 %18)
%20 = call i32 (i32, ...) @write(i32 1, [32 x i8]* %4, i32 32)
br label %29
21: ; preds = %2
%22 = load i32, i32* %6
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 (i32, ...) @write(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 32)
%27 = load i32, i32* %24
%28 = call i32 @close(i32 %27)
br label %29
29: ; preds = %21, %11
ret i32 1
}