#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 */
struct XmlNode {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ ModelicaFormatError(char *, char const *);
char *XmlNode_getXML(struct XmlNode *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
size_t strlen(char *);
void XmlNode_toFile(struct XmlNode *node, const char *fileName) {
  FILE *f = fopen(fileName, "w+b");
  if (f) {
    char *buffer = XmlNode_getXML(node);
    size_t len = strlen(buffer);
    if (buffer) {
      fprintf(f, "<?xml version=\"1.0\" encoding=\"%s\"?>", "UTF-8");
      fwrite(buffer, sizeof(char), len, f);
      free(buffer);
    }
    fclose(f);
  } else {
    ModelicaFormatError("Error: Cannot write to \"%s\"\n", fileName);
  }
}


x86 assembly (clang, -O0):
<XmlNode_toFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1218 <XmlNode_toFile+0x98>
mov    -0x8(%rbp),%rdi
call   1070 <XmlNode_getXML@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     120a <XmlNode_toFile+0x8a>
mov    -0x18(%rbp),%rdi
lea    0xe25(%rip),%rsi
lea    0xe42(%rip),%rdx
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1228 <XmlNode_toFile+0xa8>
mov    -0x10(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1080 <ModelicaFormatError@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XmlNode_toFile>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11fb <XmlNode_toFile+0x7b>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <XmlNode_getXML@plt>
test   %rax,%rax
je     11ee <XmlNode_toFile+0x6e>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
lea    0xe40(%rip),%rsi
lea    0xe5d(%rip),%rdx
mov    %r15,%rdi
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
lea    0xe2c(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <ModelicaFormatError@plt>

LLVM IR (-O0):
%struct.XmlNode = type { i32 }
@.str = [4 x i8] c"w+b\00"
@.str.1 = [36 x i8] c"<?xml version=\221.0\22 encoding=\22%s\22?>\00"
@.str.2 = [6 x i8] c"UTF-8\00"
@.str.3 = [29 x i8] c"Error: Cannot write to \22%s\22\0A\00"
define void @XmlNode_toFile(%struct.XmlNode* %0, i8* %1) {
%3 = alloca %struct.XmlNode*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
store %struct.XmlNode* %0, %struct.XmlNode** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %31
12: ; preds = %2
%13 = load %struct.XmlNode*, %struct.XmlNode** %3
%14 = call i8* @XmlNode_getXML(%struct.XmlNode* %13)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %7
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %28
19: ; preds = %12
%20 = load i32*, i32** %5
%21 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%22 = load i8*, i8** %6
%23 = load i64, i64* %7
%24 = load i32*, i32** %5
%25 = call i32 @fwrite(i8* %22, i32 1, i64 %23, i32* %24)
%26 = load i8*, i8** %6
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %19, %12
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
br label %34
31: ; preds = %2
%32 = load i8*, i8** %4
%33 = call i32 @ModelicaFormatError(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %28
ret void
}

LLVM IR (-O2):
%struct.XmlNode = type { i32 }
@.str = [4 x i8] c"w+b\00"
@.str.1 = [36 x i8] c"<?xml version=\221.0\22 encoding=\22%s\22?>\00"
@.str.2 = [6 x i8] c"UTF-8\00"
@.str.3 = [29 x i8] c"Error: Cannot write to \22%s\22\0A\00"
define void @XmlNode_toFile(%struct.XmlNode* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = tail call i8* @XmlNode_getXML(%struct.XmlNode* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i64 @strlen(i8* %6)
%10 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @fwrite(i8* %6, i32 1, i64 %9, i32* %3)
%12 = tail call i32 @free(i8* %6)
br label %13
13: ; preds = %8, %5
%14 = tail call i32 @fclose(i32* %3)
br label %17
15: ; preds = %2
%16 = tail call i32 @ModelicaFormatError(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %17
17: ; preds = %15, %13
ret void
}