#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 open(char const *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int open_pipe(const char *pipe_name, int flag) {
  printf("Opening pipe [%s]...", pipe_name);
  int pipe = open(pipe_name, flag);
  if (pipe == -1) {
    perror("Cannot open input pipe");
    return -1;
  }
  printf("OK\n");
  return pipe;
}


x86 assembly (clang, -O0):
<open_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1182 <open_pipe+0x52>
lea    0xea4(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <open_pipe+0x66>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_pipe>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xeb1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     117f <open_pipe+0x3f>
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8f(%rip),%rdi
call   1060 <perror@plt>
jmp    1176 <open_pipe+0x36>

LLVM IR (-O0):
@.str = [21 x i8] c"Opening pipe [%s]...\00"
@.str.1 = [23 x i8] c"Cannot open input pipe\00"
@.str.2 = [4 x i8] c"OK\0A\00"
define i32 @open_pipe(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* %6
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %14
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [21 x i8] c"Opening pipe [%s]...\00"
@.str.1 = [23 x i8] c"Cannot open input pipe\00"
@str = [3 x i8] c"OK\00"
define i32 @open_pipe(i8* %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32 @open(i8* %0, i32 %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
ret i32 %4
}