#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 *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strncat(char *, char const *, int);
void writeToListFile(const char *path, const char *filename) {
  if (path == NULL || filename == NULL) {
    printf("ERROR: Could not read filesystem\n");
    return;
  }
  char filePath[255];
  filePath[0] = 0;
  strncat(filePath, path, 255);
  strncat(filePath, ".list", 6);
  FILE *file = fopen(filePath, "a");
  fprintf(file, "%s\n", filename);
  fclose(file);
}


x86 assembly (clang, -O0):
<writeToListFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1179 <writeToListFile+0x29>
cmpq   $0x0,-0x10(%rbp)
jne    118a <writeToListFile+0x3a>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
jmp    11fb <writeToListFile+0xab>
movb   $0x0,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xff,%edx
call   1050 <strncat@plt>
lea    -0x110(%rbp),%rdi
lea    0xe6e(%rip),%rsi
mov    $0x6,%edx
call   1050 <strncat@plt>
lea    -0x110(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe40(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeToListFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
test   %rdi,%rdi
je     11cd <writeToListFile+0x7d>
mov    %rsi,%r15
test   %rsi,%rsi
je     11cd <writeToListFile+0x7d>
mov    %rdi,%rsi
movb   $0x0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xff,%edx
call   1050 <strncat@plt>
lea    0xe79(%rip),%rsi
mov    %r14,%rdi
mov    $0x6,%edx
call   1050 <strncat@plt>
lea    0xe6b(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe5b(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe38(%rip),%rdi
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"ERROR: Could not read filesystem\0A\00"
@.str.1 = [6 x i8] c".list\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @writeToListFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [255 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9, %2
%13 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %28
14: ; preds = %9
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
store i8 0, i8* %15
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%17 = load i8*, i8** %3
%18 = call i32 @strncat(i8* %16, i8* %17, i32 255)
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%20 = call i32 @strncat(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = load i8*, i8** %4
%25 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %14, %12
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c".list\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@str = [33 x i8] c"ERROR: Could not read filesystem\00"
define void @writeToListFile(i8* %0, i8* %1) {
%3 = alloca [255 x i8]
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %16
9: ; preds = %2
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
store i8 0, i8* %10
%11 = call i32 @strncat(i8* %10, i8* %0, i32 255)
%12 = call i32 @strncat(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
%13 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%15 = call i32 @fclose(i32* %13)
br label %16
16: ; preds = %9, %7
ret void
}