#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *out_file;
  int count = 1;
  char buf[80];
  out_file = fopen("mypipe", "w");
  if (out_file == NULL) {
    printf("Error opening pipe.");
    return 0;
  }
  sprintf(buf, "this is test data for the named pipe example\n");
  fwrite(buf, 1, 80, out_file);
  fclose(out_file);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    0xe8c(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a7 <main+0x57>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d7 <main+0x87>
lea    -0x70(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x50,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
lea    0xeb4(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a2 <main+0x62>
mov    %rax,%rbx
movups 0xed4(%rip),%xmm0
movups %xmm0,0x1e(%rsp)
movups 0xeba(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xe9e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x50,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11ae <main+0x6e>
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"mypipe\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [20 x i8] c"Error opening pipe.\00"
@.str.3 = [46 x i8] c"this is test data for the named pipe example\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
%9 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %22
14: ; preds = %2
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%16 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32 @fwrite(i8* %17, i32 1, i32 80, i32* %18)
%20 = load i32*, i32** %6
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %14, %12
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [7 x i8] c"mypipe\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [20 x i8] c"Error opening pipe.\00"
@.str.3 = [46 x i8] c"this is test data for the named pipe example\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %12
9: ; preds = %2
%10 = call i32 @fwrite(i8* %4, i32 1, i32 80, i32* %5)
%11 = tail call i32 @fclose(i32* %5)
br label %12
12: ; preds = %9, %7
ret i32 0
}