#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_message(char *filename) {
  FILE *f, *f2;
  printf("converting message %s\n", filename);
  if ((f = open_file(filename)) == NULL)
    return;
  if ((f2 = create_file(filename)) == NULL) {
    fclose(f);
    return;
  }
  save_str(f, f2, "mtime");
  save_str(f, f2, "deleted");
  save_str(f, f2, "flags");
  save_str(f, f2, "from");
  save_str(f, f2, "anon");
  save_str(f, f2, "deleted_by");
  save_str(f, f2, "subject");
  save_strlist(f, f2, "to");
  save_strlist(f, f2, "msg");
  save_str(f, f2, "reply_number");
  fclose(f);
  fclose(f2);
  rename_file(filename);
}


x86 assembly (clang, -O0):
<convert_message>:
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_message+0x38>
jmp    12b0 <convert_message+0x140>
mov    -0x8(%rbp),%rdi
call   1090 <create_file@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cd <convert_message+0x5d>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12b0 <convert_message+0x140>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe3b(%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    0xe21(%rip),%rdx
call   1030 <save_str@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe13(%rip),%rdx
call   1030 <save_str@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe04(%rip),%rdx
call   1030 <save_str@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdf5(%rip),%rdx
call   1030 <save_str@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdec(%rip),%rdx
call   1030 <save_str@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xde0(%rip),%rdx
call   1070 <save_strlist@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdcf(%rip),%rdx
call   1070 <save_strlist@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdbf(%rip),%rdx
call   1030 <save_str@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_message>:
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     1280 <convert_message+0x110>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <create_file@plt>
test   %rax,%rax
je     1286 <convert_message+0x116>
mov    %rax,%r15
lea    0xe61(%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    0xe4b(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <save_str@plt>
lea    0xe3f(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <save_str@plt>
lea    0xe32(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <save_str@plt>
lea    0xe25(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <save_str@plt>
lea    0xe1e(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <save_str@plt>
lea    0xe14(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <save_strlist@plt>
lea    0xe05(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <save_strlist@plt>
lea    0xdf7(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <save_str@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 = [23 x i8] c"converting message %s\0A\00"
@.str.1 = [6 x i8] c"mtime\00"
@.str.2 = [8 x i8] c"deleted\00"
@.str.3 = [6 x i8] c"flags\00"
@.str.4 = [5 x i8] c"from\00"
@.str.5 = [5 x i8] c"anon\00"
@.str.6 = [11 x i8] c"deleted_by\00"
@.str.7 = [8 x i8] c"subject\00"
@.str.8 = [3 x i8] c"to\00"
@.str.9 = [4 x i8] c"msg\00"
@.str.10 = [13 x i8] c"reply_number\00"
define void @convert_message(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 ([23 x i8], [23 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 %55
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 %55
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 ([6 x i8], [6 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 ([8 x i8], [8 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 ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32*, i32** %3
%32 = load i32*, i32** %4
%33 = call i32 @save_str(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_str(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_str(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 ([3 x i8], [3 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 ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%46 = load i32*, i32** %3
%47 = load i32*, i32** %4
%48 = call i32 @save_str(i32* %46, i32* %47, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%49 = load i32*, i32** %3
%50 = call i32 @fclose(i32* %49)
%51 = load i32*, i32** %4
%52 = call i32 @fclose(i32* %51)
%53 = load i8*, i8** %2
%54 = call i32 @rename_file(i8* %53)
br label %55
55: ; preds = %18, %15, %10
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"converting message %s\0A\00"
@.str.1 = [6 x i8] c"mtime\00"
@.str.2 = [8 x i8] c"deleted\00"
@.str.3 = [6 x i8] c"flags\00"
@.str.4 = [5 x i8] c"from\00"
@.str.5 = [5 x i8] c"anon\00"
@.str.6 = [11 x i8] c"deleted_by\00"
@.str.7 = [8 x i8] c"subject\00"
@.str.8 = [3 x i8] c"to\00"
@.str.9 = [4 x i8] c"msg\00"
@.str.10 = [13 x i8] c"reply_number\00"
define void @convert_message(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 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 %24, 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 %24
10: ; preds = %5
%11 = tail call i32 @save_str(i32* %3, i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @save_str(i32* %3, i32* %6, i8* getelementptr inbounds ([8 x i8], [8 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 ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i32 @save_str(i32* %3, i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @save_str(i32* %3, i32* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%17 = tail call i32 @save_str(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 ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%19 = tail call i32 @save_strlist(i32* %3, i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%20 = tail call i32 @save_str(i32* %3, i32* %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%21 = tail call i32 @fclose(i32* %3)
%22 = tail call i32 @fclose(i32* %6)
%23 = tail call i32 @rename_file(i8* %0)
br label %24
24: ; preds = %1, %10, %8
ret void
}