#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, char);
int /*<<< orphan*/ perror(char *);
void storeData(const char *data, char *path) {
  FILE *file = fopen(path, "a");
  if (file == NULL) {
    perror("Could not open file");
  } else {
    fprintf(file, "%s%c", data, '\0');
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<storeData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1180 <storeData+0x40>
lea    0xe8c(%rip),%rdi
call   1060 <perror@plt>
jmp    1196 <storeData+0x56>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe87(%rip),%rsi
xor    %ecx,%ecx
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<storeData>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xeaf(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1184 <storeData+0x44>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
jmp    1175 <storeData+0x35>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [20 x i8] c"Could not open file\00"
@.str.2 = [5 x i8] c"%s%c\00"
define void @storeData(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %16
12: ; preds = %2
%13 = load i32*, i32** %5
%14 = load i8*, i8** %3
%15 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %14, i8 signext 0)
br label %16
16: ; preds = %12, %10
%17 = load i32*, i32** %5
%18 = call i32 @fclose(i32* %17)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@.str.1 = [20 x i8] c"Could not open file\00"
@.str.2 = [5 x i8] c"%s%c\00"
define void @storeData(i8* %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %9
7: ; preds = %2
%8 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8 signext 0)
br label %9
9: ; preds = %7, %5
%10 = tail call i32 @fclose(i32* %3)
ret void
}