#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*/ FIONREAD;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
void getPipeSize(int pipe_in, int pipe_out) {
  int buf_in_size;
  int buf_out_size;
  if (ioctl(pipe_in, FIONREAD, &buf_in_size) < 0) {
    perror("Error \n");
    exit(0);
  }
  printf(" Pipe Buffer IN Size %d \n", (buf_in_size));
  if (ioctl(pipe_out, FIONREAD, &buf_out_size) < 0) {
    perror("Error \n");
    exit(0);
  }
  printf(" Pipe Buffer OUT Size %d \n", (buf_out_size));
}


x86 assembly (clang, -O0):
<getPipeSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1180 <getPipeSize+0x40>
lea    0xe8c(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%esi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11c1 <getPipeSize+0x81>
lea    0xe4b(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%esi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPipeSize>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    0x2e9b(%rip),%r14
mov    (%r14),%esi
lea    0x4(%rsp),%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
js     1198 <getPipeSize+0x58>
mov    0x4(%rsp),%esi
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
mov    (%r14),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     1198 <getPipeSize+0x58>
mov    (%rsp),%esi
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe61(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@FIONREAD = global i32 0
@.str = [8 x i8] c"Error \0A\00"
@.str.1 = [26 x i8] c" Pipe Buffer IN Size %d \0A\00"
@.str.2 = [27 x i8] c" Pipe Buffer OUT Size %d \0A\00"
define void @getPipeSize(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* @FIONREAD
%9 = call i64 @ioctl(i32 %7, i32 %8, i32* %5)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = load i32, i32* %5
%16 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %4
%18 = load i32, i32* @FIONREAD
%19 = call i64 @ioctl(i32 %17, i32 %18, i32* %6)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %14
%25 = load i32, i32* %6
%26 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %25)
ret void
}

LLVM IR (-O2):
@FIONREAD = global i32 0
@.str = [8 x i8] c"Error \0A\00"
@.str.1 = [26 x i8] c" Pipe Buffer IN Size %d \0A\00"
@.str.2 = [27 x i8] c" Pipe Buffer OUT Size %d \0A\00"
define void @getPipeSize(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @FIONREAD
%8 = call i64 @ioctl(i32 %0, i32 %7, i32* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %2
%14 = load i32, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @FIONREAD
%17 = call i64 @ioctl(i32 %1, i32 %16, i32* %4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %13
%23 = load i32, i32* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %23)
ret void
}