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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, char, size_t);
void fifo_common_finish(int fd, char **buf, size_t *used, size_t *size) {
  if (fd >= 0)
    close(fd);
  if (!*buf)
    return;
  memset(*buf, '\0', *size);
  free(*buf);
  *buf = NULL;
  *used = 0;
  *size = 0;
}


x86 assembly (clang, -O0):
<fifo_common_finish>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1159 <fifo_common_finish+0x29>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    116c <fifo_common_finish+0x3c>
jmp    11ae <fifo_common_finish+0x7e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fifo_common_finish>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
test   %edi,%edi
js     1147 <fifo_common_finish+0x17>
call   1050 <close@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
je     1176 <fifo_common_finish+0x46>
mov    (%r15),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
movq   $0x0,(%rbx)
movq   $0x0,(%r14)
movq   $0x0,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @fifo_common_finish(i32 %0, i8** %1, i64* %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i64*
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
%9 = load i32, i32* %5
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = load i32, i32* %5
%13 = call i32 @close(i32 %12)
br label %14
14: ; preds = %11, %4
%15 = load i8**, i8*** %6
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %14
br label %31
19: ; preds = %14
%20 = load i8**, i8*** %6
%21 = load i8*, i8** %20
%22 = load i64*, i64** %8
%23 = load i64, i64* %22
%24 = call i32 @memset(i8* %21, i8 signext 0, i64 %23)
%25 = load i8**, i8*** %6
%26 = load i8*, i8** %25
%27 = call i32 @free(i8* %26)
%28 = load i8**, i8*** %6
store i8* null, i8** %28
%29 = load i64*, i64** %7
store i64 0, i64* %29
%30 = load i64*, i64** %8
store i64 0, i64* %30
br label %31
31: ; preds = %19, %18
ret void
}

LLVM IR (-O2):
define void @fifo_common_finish(i32 %0, i8** nocapture %1, i64* nocapture writeonly %2, i64* nocapture %3) {
%5 = icmp sgt i32 %0, -1
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @close(i32 %0)
br label %8
8: ; preds = %6, %4
%9 = load i8*, i8** %1
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = load i64, i64* %3
%13 = tail call i32 @memset(i8* %9, i8 signext 0, i64 %12)
%14 = load i8*, i8** %1
%15 = tail call i32 @free(i8* %14)
store i8* null, i8** %1
store i64 0, i64* %2
store i64 0, i64* %3
br label %16
16: ; preds = %8, %11
ret void
}