#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*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ write_xml_header(int /*<<< orphan*/ *);
int /*<<< orphan*/ write_xml_meta(int /*<<< orphan*/ *, char *);
void write_xmlerror(char *filename, char *error) {
  FILE *file;
  int pipe_flag;
  pipe_flag = 0;
  if (!strcmp(filename, "STDOUT")) {
    file = stdout;
    pipe_flag = 1;
  } else if (!(file = fopen(filename, "w")))
    return;
  write_xml_header(file);
  write_xml_meta(file, error);
  fprintf(file, "</RESOURCE>\n");
  fprintf(file, "</VOTABLE>\n");
  if (!pipe_flag)
    fclose(file);
  return;
}


x86 assembly (clang, -O0):
<write_xmlerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11aa <write_xmlerror+0x4a>
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    11d2 <write_xmlerror+0x72>
mov    -0x8(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cd <write_xmlerror+0x6d>
jmp    1220 <write_xmlerror+0xc0>
jmp    11d2 <write_xmlerror+0x72>
mov    -0x18(%rbp),%rdi
call   1030 <write_xml_header@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <write_xml_meta@plt>
mov    -0x18(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   1060 <fprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    121b <write_xmlerror+0xbb>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1220 <write_xmlerror+0xc0>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_xmlerror>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe8f(%rip),%rsi
call   1050 <strcmp@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1195 <write_xmlerror+0x35>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119f <write_xmlerror+0x3f>
jmp    11f4 <write_xmlerror+0x94>
mov    0x2e44(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1030 <write_xml_header@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <write_xml_meta@plt>
lea    0xe50(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe44(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
test   %ebp,%ebp
je     11f4 <write_xmlerror+0x94>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fclose@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"STDOUT\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"</RESOURCE>\0A\00"
@.str.3 = [12 x i8] c"</VOTABLE>\0A\00"
define void @write_xmlerror(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = call i32 @strcmp(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = load i32*, i32** @stdout
store i32* %11, i32** %5
store i32 1, i32* %6
br label %18
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %12
br label %34
17: ; preds = %12
br label %18
18: ; preds = %17, %10
%19 = load i32*, i32** %5
%20 = call i32 @write_xml_header(i32* %19)
%21 = load i32*, i32** %5
%22 = load i8*, i8** %4
%23 = call i32 @write_xml_meta(i32* %21, i8* %22)
%24 = load i32*, i32** %5
%25 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32*, i32** %5
%27 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %18
%31 = load i32*, i32** %5
%32 = call i32 @fclose(i32* %31)
br label %33
33: ; preds = %30, %18
br label %34
34: ; preds = %33, %16
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"STDOUT\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"</RESOURCE>\0A\00"
@.str.3 = [12 x i8] c"</VOTABLE>\0A\00"
define void @write_xmlerror(i8* nocapture %0, i8* %1) {
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = load i32*, i32** @stdout
br label %10
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %18, label %10
10: ; preds = %7, %5
%11 = phi i32* [ %8, %7 ], [ %6, %5 ]
%12 = tail call i32 @write_xml_header(i32* %11)
%13 = tail call i32 @write_xml_meta(i32* %11, i8* %1)
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 12, i64 1, i32* %11)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 11, i64 1, i32* %11)
br i1 %4, label %18, label %16
16: ; preds = %10
%17 = tail call i32 @fclose(i32* %11)
br label %18
18: ; preds = %10, %16, %7
ret void
}