#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stderr;
int save_to_file(const char *filename, const char *content) {
  if (!content) {
    fprintf(stderr, "[!!] Invalid content [!!]\n");
    return -1;
  }
  FILE *fp = fopen(filename, "a");
  if (!fp) {
    fprintf(stderr, "[!!] Error opening the file %s : ", filename);
    perror("");
    return -1;
  }
  fprintf(fp, "%s", content);
  fclose(fp);
  fflush(fp);
  return 0;
}


x86 assembly (clang, -O0):
<save_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118f <save_to_file+0x3f>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rdi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <save_to_file+0xc1>
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e2 <save_to_file+0x92>
mov    0x2e2b(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    0xe49(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <save_to_file+0xc1>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_to_file>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     11b3 <save_to_file+0x43>
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe94(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11de <save_to_file+0x6e>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
xor    %eax,%eax
jmp    11d8 <save_to_file+0x68>
mov    0x2e26(%rip),%rax
mov    (%rax),%rcx
lea    0xe3c(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dfb(%rip),%rax
mov    (%rax),%rdi
lea    0xe2e(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe1a(%rip),%rdi
call   1080 <perror@plt>
jmp    11d3 <save_to_file+0x63>

LLVM IR (-O0):
@stderr = global i32* null
@.str = [27 x i8] c"[!!] Invalid content [!!]\0A\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [34 x i8] c"[!!] Error opening the file %s : \00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [3 x i8] c"%s\00"
define i32 @save_to_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32*, i32** @stderr
%11 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
12: ; preds = %2
%13 = load i8*, i8** %4
%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** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i32*, i32** @stderr
%19 = load i8*, i8** %4
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
22: ; preds = %12
%23 = load i32*, i32** %6
%24 = load i8*, i8** %5
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
%28 = load i32*, i32** %6
%29 = call i32 @fflush(i32* %28)
store i32 0, i32* %3
br label %30
30: ; preds = %22, %17, %9
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [27 x i8] c"[!!] Invalid content [!!]\0A\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [34 x i8] c"[!!] Error opening the file %s : \00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @save_to_file(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32*, i32** @stderr
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 26, i64 1, i32* %5)
br label %18
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 %10, label %14
10: ; preds = %7
%11 = load i32*, i32** @stderr
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%13 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %18
14: ; preds = %7
%15 = tail call i32 @fputs(i8* %1, i32* %8)
%16 = tail call i32 @fclose(i32* %8)
%17 = tail call i32 @fflush(i32* %8)
br label %18
18: ; preds = %10, %14, %4
%19 = phi i32 [ -1, %4 ], [ 0, %14 ], [ -1, %10 ]
ret i32 %19
}