#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*/ errno;
int /*<<< orphan*/ *fopen(char const *const, char *);
int /*<<< orphan*/ pm_error(char *, char const *const, int /*<<< orphan*/,
                            int /*<<< orphan*/);
int /*<<< orphan*/ *stdout;
scalar_t__ streq(char const *const, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
FILE *pm_openw(const char *const name) {
  FILE *f;
  if (streq(name, "-"))
    f = stdout;
  else {
    f = fopen(name, "wb");
    if (f == NULL)
      pm_error("Unable to open file '%s' for writing.  "
               "fopen() returns errno %d (%s)",
               name, errno, strerror(errno));
  }
  return f;
}


x86 assembly (clang, -O0):
<pm_openw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1030 <streq@plt>
cmp    $0x0,%rax
je     1179 <pm_openw+0x39>
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    11d4 <pm_openw+0x94>
mov    -0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cf <pm_openw+0x8f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
lea    0xe3b(%rip),%rdi
call   1060 <pm_error@plt>
jmp    11d4 <pm_openw+0x94>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pm_openw>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeb3(%rip),%rsi
call   1030 <streq@plt>
test   %rax,%rax
je     1163 <pm_openw+0x23>
mov    0x2e7a(%rip),%rax
mov    (%rax),%rax
jmp    119c <pm_openw+0x5c>
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
jne    119c <pm_openw+0x5c>
mov    0x2e62(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1050 <strerror@plt>
lea    0xe77(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
call   1060 <pm_error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [69 x i8] c"Unable to open file '%s' for writing. fopen() returns errno %d (%s)\00"
@errno = global i32 0
define i32* @pm_openw(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @streq(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32*, i32** @stdout
store i32* %8, i32** %3
br label %21
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = load i32, i32* @errno
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @pm_error(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32 %16, i32 %18)
br label %20
20: ; preds = %14, %9
br label %21
21: ; preds = %20, %7
%22 = load i32*, i32** %3
ret i32* %22
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [69 x i8] c"Unable to open file '%s' for writing. fopen() returns errno %d (%s)\00"
@errno = global i32 0
define i32* @pm_openw(i8* %0) {
%2 = tail call i64 @streq(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = load i32*, i32** @stdout
br label %13
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = tail call i32 @pm_error(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %10, i32 %11)
br label %13
13: ; preds = %6, %9, %4
%14 = phi i32* [ %5, %4 ], [ null, %9 ], [ %7, %6 ]
ret i32* %14
}