#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*/ *create_file(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_file(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rename_file(char *);
int /*<<< orphan*/ save_str(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ save_strlist(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                char *);
void convert_roomdata(char *filename) {
  FILE *f, *f2;
  printf("converting roomdata %s\n", filename);
  if ((f = open_file(filename)) == NULL)
    return;
  if ((f2 = create_file(filename)) == NULL) {
    fclose(f);
    return;
  }
  save_str(f, f2, "name");
  save_str(f, f2, "generation");
  save_str(f, f2, "flags");
  save_str(f, f2, "roominfo_changed");
  save_strlist(f, f2, "info");
  save_strlist(f, f2, "room_aides");
  save_strlist(f, f2, "invited");
  save_strlist(f, f2, "kicked");
  save_strlist(f, f2, "chat_history");
  fclose(f);
  fclose(f2);
  rename_file(filename);
}


x86 assembly (clang, -O0):
<convert_roomdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <open_file@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a8 <convert_roomdata+0x38>
jmp    129c <convert_roomdata+0x12c>
mov    -0x8(%rbp),%rdi
call   1090 <create_file@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cd <convert_roomdata+0x5d>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    129c <convert_roomdata+0x12c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe3c(%rip),%rdx
call   1030 <save_str@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe2d(%rip),%rdx
call   1030 <save_str@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe24(%rip),%rdx
call   1030 <save_str@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe16(%rip),%rdx
call   1030 <save_str@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe13(%rip),%rdx
call   1070 <save_strlist@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe04(%rip),%rdx
call   1070 <save_strlist@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdfb(%rip),%rdx
call   1070 <save_strlist@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdef(%rip),%rdx
call   1070 <save_strlist@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xde2(%rip),%rdx
call   1070 <save_strlist@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rdi
call   1080 <rename_file@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_roomdata>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe81(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <open_file@plt>
test   %rax,%rax
je     126e <convert_roomdata+0xfe>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <create_file@plt>
test   %rax,%rax
je     1274 <convert_roomdata+0x104>
mov    %rax,%r15
lea    0xe62(%rip),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <save_str@plt>
lea    0xe55(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <save_str@plt>
lea    0xe4e(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <save_str@plt>
lea    0xe42(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <save_str@plt>
lea    0xe41(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <save_strlist@plt>
lea    0xe34(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <save_strlist@plt>
lea    0xe2d(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <save_strlist@plt>
lea    0xe23(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <save_strlist@plt>
lea    0xe18(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <save_strlist@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <rename_file@plt>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"converting roomdata %s\0A\00"
@.str.1 = [5 x i8] c"name\00"
@.str.2 = [11 x i8] c"generation\00"
@.str.3 = [6 x i8] c"flags\00"
@.str.4 = [17 x i8] c"roominfo_changed\00"
@.str.5 = [5 x i8] c"info\00"
@.str.6 = [11 x i8] c"room_aides\00"
@.str.7 = [8 x i8] c"invited\00"
@.str.8 = [7 x i8] c"kicked\00"
@.str.9 = [13 x i8] c"chat_history\00"
define void @convert_roomdata(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %2
%8 = call i32* @open_file(i8* %7)
store i32* %8, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
br label %52
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i32* @create_file(i8* %12)
store i32* %13, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32*, i32** %3
%17 = call i32 @fclose(i32* %16)
br label %52
18: ; preds = %11
%19 = load i32*, i32** %3
%20 = load i32*, i32** %4
%21 = call i32 @save_str(i32* %19, i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32*, i32** %3
%23 = load i32*, i32** %4
%24 = call i32 @save_str(i32* %22, i32* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32*, i32** %3
%26 = load i32*, i32** %4
%27 = call i32 @save_str(i32* %25, i32* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32*, i32** %3
%29 = load i32*, i32** %4
%30 = call i32 @save_str(i32* %28, i32* %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32*, i32** %3
%32 = load i32*, i32** %4
%33 = call i32 @save_strlist(i32* %31, i32* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32*, i32** %3
%35 = load i32*, i32** %4
%36 = call i32 @save_strlist(i32* %34, i32* %35, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%37 = load i32*, i32** %3
%38 = load i32*, i32** %4
%39 = call i32 @save_strlist(i32* %37, i32* %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%40 = load i32*, i32** %3
%41 = load i32*, i32** %4
%42 = call i32 @save_strlist(i32* %40, i32* %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%43 = load i32*, i32** %3
%44 = load i32*, i32** %4
%45 = call i32 @save_strlist(i32* %43, i32* %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%46 = load i32*, i32** %3
%47 = call i32 @fclose(i32* %46)
%48 = load i32*, i32** %4
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %2
%51 = call i32 @rename_file(i8* %50)
br label %52
52: ; preds = %18, %15, %10
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"converting roomdata %s\0A\00"
@.str.1 = [5 x i8] c"name\00"
@.str.2 = [11 x i8] c"generation\00"
@.str.3 = [6 x i8] c"flags\00"
@.str.4 = [17 x i8] c"roominfo_changed\00"
@.str.5 = [5 x i8] c"info\00"
@.str.6 = [11 x i8] c"room_aides\00"
@.str.7 = [8 x i8] c"invited\00"
@.str.8 = [7 x i8] c"kicked\00"
@.str.9 = [13 x i8] c"chat_history\00"
define void @convert_roomdata(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32* @open_file(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = tail call i32* @create_file(i8* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @fclose(i32* %3)
br label %23
10: ; preds = %5
%11 = tail call i32 @save_str(i32* %3, i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @save_str(i32* %3, i32* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @save_str(i32* %3, i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @save_str(i32* %3, i32* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i32 @save_strlist(i32* %3, i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @save_strlist(i32* %3, i32* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%17 = tail call i32 @save_strlist(i32* %3, i32* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%18 = tail call i32 @save_strlist(i32* %3, i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%19 = tail call i32 @save_strlist(i32* %3, i32* %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%20 = tail call i32 @fclose(i32* %3)
%21 = tail call i32 @fclose(i32* %6)
%22 = tail call i32 @rename_file(i8* %0)
br label %23
23: ; preds = %1, %10, %8
ret void
}