#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 close(int);
int /*<<< orphan*/ exit(int);
int munmap(char *, int);
int /*<<< orphan*/ perror(char *);
void buffer_close(int fileno, char *start) {
  if ((munmap(start, 32768)) == -1) {
    perror("munmap failed on shared buffer");
    exit(1);
  }
  if ((close(fileno)) == -1) {
    perror("close failed on shared buffer file handle");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<buffer_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x8000,%esi
call   1040 <munmap@plt>
cmp    $0xffffffff,%eax
jne    117c <buffer_close+0x3c>
lea    0xe93(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    11a3 <buffer_close+0x63>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_close>:
push   %rbx
mov    %edi,%ebx
mov    %rsi,%rdi
mov    $0x8000,%esi
call   1040 <munmap@plt>
cmp    $0xffffffff,%eax
je     1163 <buffer_close+0x23>
mov    %ebx,%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
je     116c <buffer_close+0x2c>
pop    %rbx
ret
lea    0xe96(%rip),%rdi
jmp    1173 <buffer_close+0x33>
lea    0xeac(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"munmap failed on shared buffer\00"
@.str.1 = [42 x i8] c"close failed on shared buffer file handle\00"
define void @buffer_close(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = call i32 @munmap(i8* %5, i32 32768)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i32, i32* %3
%13 = call i32 @close(i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"munmap failed on shared buffer\00"
@.str.1 = [42 x i8] c"close failed on shared buffer file handle\00"
define void @buffer_close(i32 %0, i8* %1) {
%3 = tail call i32 @munmap(i8* %1, i32 32768)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i32 @close(i32 %0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8
ret void
}