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

/* Variables and functions */
struct Stream_t *buf_init(struct Stream_t *, int, int, int);
int /*<<< orphan*/ free_stream(struct Stream_t **);
void bufferize(struct Stream_t **Dir) {
  struct Stream_t *BDir;
  if (!*Dir)
    return;
  BDir = buf_init(*Dir, 64 * 16384, 512, 32);
  if (!BDir) {
    free_stream(Dir);
    *Dir = NULL;
  } else
    *Dir = BDir;
}


x86 assembly (clang, -O0):
<bufferize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    113f <bufferize+0x1f>
jmp    118d <bufferize+0x6d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x100000,%esi
mov    $0x200,%edx
mov    $0x20,%ecx
call   1030 <buf_init@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1182 <bufferize+0x62>
mov    -0x8(%rbp),%rdi
call   1040 <free_stream@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
jmp    118d <bufferize+0x6d>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufferize>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1156 <bufferize+0x36>
mov    $0x100000,%esi
mov    $0x200,%edx
mov    $0x20,%ecx
call   1030 <buf_init@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1153 <bufferize+0x33>
mov    %rbx,%rdi
call   1040 <free_stream@plt>
mov    %r14,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.Stream_t = type { i32 }
define void @bufferize(%struct.Stream_t** %0) {
%2 = alloca %struct.Stream_t**
%3 = alloca %struct.Stream_t*
store %struct.Stream_t** %0, %struct.Stream_t*** %2
%4 = load %struct.Stream_t**, %struct.Stream_t*** %2
%5 = load %struct.Stream_t*, %struct.Stream_t** %4
%6 = icmp ne %struct.Stream_t* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
br label %21
8: ; preds = %1
%9 = load %struct.Stream_t**, %struct.Stream_t*** %2
%10 = load %struct.Stream_t*, %struct.Stream_t** %9
%11 = call %struct.Stream_t* @buf_init(%struct.Stream_t* %10, i32 1048576, i32 512, i32 32)
store %struct.Stream_t* %11, %struct.Stream_t** %3
%12 = load %struct.Stream_t*, %struct.Stream_t** %3
%13 = icmp ne %struct.Stream_t* %12, null
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = load %struct.Stream_t**, %struct.Stream_t*** %2
%16 = call i32 @free_stream(%struct.Stream_t** %15)
%17 = load %struct.Stream_t**, %struct.Stream_t*** %2
store %struct.Stream_t* null, %struct.Stream_t** %17
br label %21
18: ; preds = %8
%19 = load %struct.Stream_t*, %struct.Stream_t** %3
%20 = load %struct.Stream_t**, %struct.Stream_t*** %2
store %struct.Stream_t* %19, %struct.Stream_t** %20
br label %21
21: ; preds = %7, %18, %14
ret void
}

LLVM IR (-O2):
%struct.Stream_t = type { i32 }
define void @bufferize(%struct.Stream_t** %0) {
%2 = load %struct.Stream_t*, %struct.Stream_t** %0
%3 = icmp eq %struct.Stream_t* %2, null
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call %struct.Stream_t* @buf_init(%struct.Stream_t* %2, i32 1048576, i32 512, i32 32)
%6 = icmp eq %struct.Stream_t* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @free_stream(%struct.Stream_t** %0)
br label %9
9: ; preds = %4, %7
store %struct.Stream_t* %5, %struct.Stream_t** %0
br label %10
10: ; preds = %1, %9
ret void
}