#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, unsigned long, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
int main() {
  int fds[2];
  if (pipe(fds) == -1) {
    fprintf(stderr, "pipe(fds) error: %s\n", strerror(errno));
  }
  unsigned long int size = 0;
  char c = 'a';
  int r = 0;
  while (1) {
    printf("%d bytes written into pipe : %d\n", size, r);
    if (write(fds[1], &c, 1) == -1) {
      break;
    }
    ++size;
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    119d <main+0x4d>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe68(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x18(%rbp)
movb   $0x61,-0x19(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11e2 <main+0x92>
jmp    11f3 <main+0xa3>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11b0 <main+0x60>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1190 <main+0x40>
mov    0x2e71(%rip),%rax
mov    (%rax),%ebx
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe7a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
movb   $0x61,0x7(%rsp)
xor    %ebx,%ebx
lea    0xe77(%rip),%r14
lea    0x7(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x1,%rbx
cmp    $0xffffffff,%eax
jne    11b0 <main+0x60>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"pipe(fds) error: %s\0A\00"
@errno = global i32 0
@.str.1 = [33 x i8] c"%d bytes written into pipe : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i64
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %9, %0
store i64 0, i64* %3
store i8 97, i8* %4
store i32 0, i32* %5
br label %15
15: ; preds = %14, %24
%16 = load i64, i64* %3
%17 = load i32, i32* %5
%18 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %16, i32 %17)
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @write(i32 %20, i8* %4, i32 1)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %15
br label %27
24: ; preds = %15
%25 = load i64, i64* %3
%26 = add i64 %25, 1
store i64 %26, i64* %3
br label %15
27: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"pipe(fds) error: %s\0A\00"
@errno = global i32 0
@.str.1 = [33 x i8] c"%d bytes written into pipe : %d\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i8
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %7, %0
store i8 97, i8* %2
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
br label %14
14: ; preds = %14, %12
%15 = phi i64 [ 0, %12 ], [ %20, %14 ]
%16 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %15, i32 0)
%17 = load i32, i32* %13
%18 = call i32 @write(i32 %17, i8* %2, i32 1)
%19 = icmp eq i32 %18, -1
%20 = add i64 %15, 1
br i1 %19, label %21, label %14
21: ; preds = %14
ret i32 0
}