#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char **argv) {
  int pipe;
  char buf[256];
  if (argc != 2) {
    printf("usage : %s <file> \n", argv[0]);
    exit(0);
  }
  if ((pipe = open(argv[1], O_RDWR)) != -1) {
    if (read(pipe, buf, sizeof(buf)) != -1) {
      printf("Data read from pipe : \n");
      printf("%s\n", buf);
    } else {
      printf("Error : read \n");
    }
    close(pipe);
  } else {
    printf("Error : open \n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1211 <main+0xc1>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11f6 <main+0xa6>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1204 <main+0xb4>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    121f <main+0xcf>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
cmp    $0x2,%edi
jne    11d7 <main+0x77>
mov    0x8(%rsi),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11ab <main+0x4b>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     11b9 <main+0x59>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
jmp    11c0 <main+0x60>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
jmp    11cc <main+0x6c>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xe1f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"usage : %s <file> \0A\00"
@O_RDWR = global i32 0
@.str.1 = [24 x i8] c"Data read from pipe : \0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [15 x i8] c"Error : read \0A\00"
@.str.4 = [15 x i8] c"Error : open \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDWR
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %6
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %37
23: ; preds = %16
%24 = load i32, i32* %6
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 256)
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %34
32: ; preds = %23
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
%35 = load i32, i32* %6
%36 = call i32 @close(i32 %35)
br label %39
37: ; preds = %16
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %39
39: ; preds = %37, %34
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"usage : %s <file> \0A\00"
@O_RDWR = global i32 0
@str = [14 x i8] c"Error : open \00"
@str.5 = [14 x i8] c"Error : read \00"
@str.6 = [23 x i8] c"Data read from pipe : \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %26, label %16
16: ; preds = %10
%17 = call i32 @read(i32 %14, i8* %4, i32 256)
%18 = icmp eq i32 %17, -1
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%21 = call i32 @puts(i8* %4)
br label %24
22: ; preds = %16
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = tail call i32 @close(i32 %14)
br label %28
26: ; preds = %10
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %26, %24
ret i32 0
}