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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ mini_free(struct MINI_Section *);
struct MINI_Section *mini_load(char *);
int /*<<< orphan*/ mini_write(int /*<<< orphan*/ *, struct MINI_Section *);
int main(int argc, char **argv) {
  struct MINI_Section *ini = mini_load("[foo]\n"
                                       "bar = baz\n"
                                       "#blabla\n");
  if (ini == NULL) {
    return -1;
  }
  FILE *f = fopen("test.ini", "w");
  mini_write(f, ini);
  fclose(f);
  mini_free(ini);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
call   1070 <mini_load@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118d <main+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <main+0x73>
lea    0xe85(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <mini_write@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <mini_free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1070 <mini_load@plt>
test   %rax,%rax
je     119d <main+0x4d>
mov    %rax,%rbx
lea    0xeaa(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <mini_write@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1040 <mini_free@plt>
xor    %eax,%eax
jmp    11a2 <main+0x52>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.MINI_Section = type { i32 }
@.str = [25 x i8] c"[foo]\0Abar = baz\0A#blabla\0A\00"
@.str.1 = [9 x i8] c"test.ini\00"
@.str.2 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.MINI_Section*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call %struct.MINI_Section* @mini_load(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store %struct.MINI_Section* %8, %struct.MINI_Section** %6
%9 = load %struct.MINI_Section*, %struct.MINI_Section** %6
%10 = icmp eq %struct.MINI_Section* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %21
12: ; preds = %2
%13 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = load %struct.MINI_Section*, %struct.MINI_Section** %6
%16 = call i32 @mini_write(i32* %14, %struct.MINI_Section* %15)
%17 = load i32*, i32** %7
%18 = call i32 @fclose(i32* %17)
%19 = load %struct.MINI_Section*, %struct.MINI_Section** %6
%20 = call i32 @mini_free(%struct.MINI_Section* %19)
br label %21
21: ; preds = %12, %11
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.MINI_Section = type { i32 }
@.str = [25 x i8] c"[foo]\0Abar = baz\0A#blabla\0A\00"
@.str.1 = [9 x i8] c"test.ini\00"
@.str.2 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call %struct.MINI_Section* @mini_load(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq %struct.MINI_Section* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @mini_write(i32* %6, %struct.MINI_Section* %3)
%8 = tail call i32 @fclose(i32* %6)
%9 = tail call i32 @mini_free(%struct.MINI_Section* %3)
br label %10
10: ; preds = %2, %5
%11 = phi i32 [ 0, %5 ], [ -1, %2 ]
ret i32 %11
}