#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*/ DIR;

/* Variables and functions */
char *alloc();
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
char *data_folder();
int /*<<< orphan*/ flog_crit(char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ release(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
void assert_data_folder_exists() {
  DIR *dir = opendir(data_folder());
  if (dir == NULL) {
    char *s = alloc();
    snprintf(s, (4 * 1024 - 32),
             "data folder %s does not exist or is unavailable\n",
             data_folder());
    flog_crit("data", s);
    release(s);
  } else {
    closedir(dir);
  }
}


x86 assembly (clang, -O0):
<assert_data_folder_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1080 <data_folder@plt>
mov    %rax,%rdi
call   1040 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11e6 <assert_data_folder_exists+0x76>
mov    $0x0,%al
call   1070 <alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <data_folder@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rcx
mov    $0xfe0,%esi
lea    0xe3d(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1030 <flog_crit@plt>
mov    -0x10(%rbp),%rdi
call   1090 <release@plt>
jmp    11ef <assert_data_folder_exists+0x7f>
mov    -0x8(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assert_data_folder_exists>:
push   %rbx
xor    %eax,%eax
call   1080 <data_folder@plt>
mov    %rax,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     118e <assert_data_folder_exists+0x1e>
mov    %rax,%rdi
pop    %rbx
jmp    1060 <closedir@plt>
xor    %eax,%eax
call   1070 <alloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <data_folder@plt>
lea    0xe5a(%rip),%rdx
mov    %rbx,%rdi
mov    $0xfe0,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
lea    0xe74(%rip),%rdi
mov    %rbx,%rsi
call   1030 <flog_crit@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1090 <release@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"data folder %s does not exist or is unavailable\0A\00"
@.str.1 = [5 x i8] c"data\00"
define void @assert_data_folder_exists() {
%1 = alloca i32*
%2 = alloca i8*
%3 = call i8* (...) @data_folder()
%4 = call i32* @opendir(i8* %3)
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = call i8* (...) @alloc()
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = call i8* (...) @data_folder()
%11 = call i32 @snprintf(i8* %9, i32 4064, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %2
%13 = call i32 @flog_crit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = call i32 @release(i8* %14)
br label %19
16: ; preds = %0
%17 = load i32*, i32** %1
%18 = call i32 @closedir(i32* %17)
br label %19
19: ; preds = %16, %7
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"data folder %s does not exist or is unavailable\0A\00"
@.str.1 = [5 x i8] c"data\00"
define void @assert_data_folder_exists() {
%1 = tail call i8* (...) @data_folder()
%2 = tail call i32* @opendir(i8* %1)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %10
4: ; preds = %0
%5 = tail call i8* (...) @alloc()
%6 = tail call i8* (...) @data_folder()
%7 = tail call i32 @snprintf(i8* %5, i32 4064, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @flog_crit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = tail call i32 @release(i8* %5)
br label %12
10: ; preds = %0
%11 = tail call i32 @closedir(i32* %2)
br label %12
12: ; preds = %10, %4
ret void
}