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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, void *, size_t, char *);
scalar_t__ munmap(void *, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror_r(int /*<<< orphan*/, char *, int);
void munmap_checked(void *addr, size_t size) {
  if (munmap(addr, size)) {
    char buf[64];
    intptr_t ignore_it = (intptr_t)strerror_r(errno, buf, sizeof(buf));
    (void)ignore_it;
    fprintf(stderr, "Error in munmap(%p, %zu): %s\n", addr, size, buf);
    assert(false);
  }
}


x86 assembly (clang, -O0):
<munmap_checked>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <munmap@plt>
cmp    $0x0,%rax
je     11ac <munmap_checked+0x6c>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
call   1050 <strerror_r@plt>
cltq
mov    %rax,-0x58(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x50(%rbp),%r8
lea    0xe60(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1030 <assert@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<munmap_checked>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <munmap@plt>
test   %rax,%rax
je     1197 <munmap_checked+0x57>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%r15
mov    %r15,%rsi
mov    $0x40,%edx
call   1050 <strerror_r@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1030 <assert@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"Error in munmap(%p, %zu): %s\0A\00"
define void @munmap_checked(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [64 x i8]
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
%8 = load i64, i64* %4
%9 = call i64 @munmap(i8* %7, i64 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%14 = call i32 @strerror_r(i32 %12, i8* %13, i32 64)
%15 = sext i32 %14 to i64
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %3
%19 = load i64, i64* %4
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %18, i64 %19, i8* %20)
%22 = call i32 @assert(i32 0)
br label %23
23: ; preds = %11, %2
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"Error in munmap(%p, %zu): %s\0A\00"
define void @munmap_checked(i8* %0, i64 %1) {
%3 = alloca [64 x i8]
%4 = tail call i64 @munmap(i8* %0, i64 %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @errno
%9 = call i32 @strerror_r(i32 %8, i8* %7, i32 64)
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1, i8* %7)
%12 = call i32 @assert(i32 0)
br label %13
13: ; preds = %6, %2
ret void
}