#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 ft_buffer {
  int dummy;
};

/* Variables and functions */
struct ft_buffer *alloc_ft_buffer(unsigned int, unsigned int);
int creat(char const *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *ft_flush_buffer_async(struct ft_buffer *, int);
int /*<<< orphan*/ stderr;
struct ft_buffer *alloc_flushed_ft_buffer(unsigned int slots, unsigned int size,
                                          const char *file, void **handle) {
  struct ft_buffer *buf = alloc_ft_buffer(slots, size);
  int fd;
  if (buf) {
    fd = creat(file, 0600);
    if (fd == -1 || !(*handle = ft_flush_buffer_async(buf, fd))) {
      fprintf(stderr, "Feather-Trace: Could not open flush file.\n");
      exit(1);
    }
  } else {
    fprintf(stderr, "Feather-Trace: Could not allocate buffer!\n");
    exit(1);
  }
  return buf;
}


x86 assembly (clang, -O0):
<alloc_flushed_ft_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <alloc_ft_buffer@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11dc <alloc_flushed_ft_buffer+0x8c>
mov    -0x10(%rbp),%rdi
mov    $0x180,%esi
call   1060 <creat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     11b8 <alloc_flushed_ft_buffer+0x68>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <ft_flush_buffer_async@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11d7 <alloc_flushed_ft_buffer+0x87>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11fb <alloc_flushed_ft_buffer+0xab>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_flushed_ft_buffer>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
call   1040 <alloc_ft_buffer@plt>
test   %rax,%rax
je     11a7 <alloc_flushed_ft_buffer+0x57>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x180,%esi
call   1060 <creat@plt>
cmp    $0xffffffff,%eax
je     1195 <alloc_flushed_ft_buffer+0x45>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <ft_flush_buffer_async@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1195 <alloc_flushed_ft_buffer+0x45>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
jmp    11b7 <alloc_flushed_ft_buffer+0x67>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.ft_buffer = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"Feather-Trace: Could not open flush file.\0A\00"
@.str.1 = [43 x i8] c"Feather-Trace: Could not allocate buffer!\0A\00"
define %struct.ft_buffer* @alloc_flushed_ft_buffer(i32 %0, i32 %1, i8* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca %struct.ft_buffer*
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8** %3, i8*** %8
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = call %struct.ft_buffer* @alloc_ft_buffer(i32 %11, i32 %12)
store %struct.ft_buffer* %13, %struct.ft_buffer** %9
%14 = load %struct.ft_buffer*, %struct.ft_buffer** %9
%15 = icmp ne %struct.ft_buffer* %14, null
br i1 %15, label %16, label %32
16: ; preds = %4
%17 = load i8*, i8** %7
%18 = call i32 @creat(i8* %17, i32 384)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = icmp eq i32 %19, -1
br i1 %20, label %27, label %21
21: ; preds = %16
%22 = load %struct.ft_buffer*, %struct.ft_buffer** %9
%23 = load i32, i32* %10
%24 = call i8* @ft_flush_buffer_async(%struct.ft_buffer* %22, i32 %23)
%25 = load i8**, i8*** %8
store i8* %24, i8** %25
%26 = icmp ne i8* %24, null
br i1 %26, label %31, label %27
27: ; preds = %21, %16
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
br label %36
32: ; preds = %4
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %31
%37 = load %struct.ft_buffer*, %struct.ft_buffer** %9
ret %struct.ft_buffer* %37
}

LLVM IR (-O2):
%struct.ft_buffer = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"Feather-Trace: Could not open flush file.\0A\00"
@.str.1 = [43 x i8] c"Feather-Trace: Could not allocate buffer!\0A\00"
define %struct.ft_buffer* @alloc_flushed_ft_buffer(i32 %0, i32 %1, i8* %2, i8** nocapture writeonly %3) {
%5 = tail call %struct.ft_buffer* @alloc_ft_buffer(i32 %0, i32 %1)
%6 = icmp eq %struct.ft_buffer* %5, null
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = tail call i32 @creat(i8* %2, i32 384)
%9 = icmp eq i32 %8, -1
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i8* @ft_flush_buffer_async(%struct.ft_buffer* %5, i32 %8)
store i8* %11, i8** %3
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %21
13: ; preds = %10, %7
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %4
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %10
ret %struct.ft_buffer* %5
}