#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*/ get_semaphore_name();
scalar_t__ munmap(int *, int);
int /*<<< orphan*/ shm_error(char *);
scalar_t__ shm_unlink(int /*<<< orphan*/);
int /*<<< orphan*/ trace_flow(char *);
void unmap_semaphore(int *semaphore) {
  if (0) {
    trace_flow("ENTERING: unmap_semaphore");
  }
  if (munmap(semaphore, sizeof(int)) != 0) {
    shm_error("munmap");
  }
  if (shm_unlink(get_semaphore_name()) != 0) {
    shm_error("shm_unlink");
  }
  if (0) {
    trace_flow("LEAVING: unmap_semaphore");
  }
}


x86 assembly (clang, -O0):
<unmap_semaphore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1050 <munmap@plt>
cmp    $0x0,%rax
je     1170 <unmap_semaphore+0x30>
lea    0xe95(%rip),%rdi
call   1030 <shm_error@plt>
mov    $0x0,%al
call   1040 <get_semaphore_name@plt>
mov    %eax,%edi
call   1060 <shm_unlink@plt>
cmp    $0x0,%rax
je     1194 <unmap_semaphore+0x54>
lea    0xe78(%rip),%rdi
call   1030 <shm_error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unmap_semaphore>:
push   %rax
mov    $0x4,%esi
call   1050 <munmap@plt>
test   %rax,%rax
je     115c <unmap_semaphore+0x1c>
lea    0xea9(%rip),%rdi
call   1030 <shm_error@plt>
xor    %eax,%eax
call   1040 <get_semaphore_name@plt>
mov    %eax,%edi
call   1060 <shm_unlink@plt>
test   %rax,%rax
je     117c <unmap_semaphore+0x3c>
lea    0xe91(%rip),%rdi
pop    %rax
jmp    1030 <shm_error@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [7 x i8] c"munmap\00"
@.str.1 = [11 x i8] c"shm_unlink\00"
define void @unmap_semaphore(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
%3 = load i32*, i32** %2
%4 = call i64 @munmap(i32* %3, i32 4)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @shm_error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = call i32 (...) @get_semaphore_name()
%10 = call i64 @shm_unlink(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @shm_error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"munmap\00"
@.str.1 = [11 x i8] c"shm_unlink\00"
define void @unmap_semaphore(i32* %0) {
%2 = tail call i64 @munmap(i32* %0, i32 4)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @shm_error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i32 (...) @get_semaphore_name()
%8 = tail call i64 @shm_unlink(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @shm_error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
ret void
}