#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*/ IPC_RMID;
int /*<<< orphan*/ msgctl(int const, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ shmctl(int const, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ shmdt(void *);
void cleanUp(const int shmid, const int msqid, void *sharedMemPtr) {
  printf("Detaching from shared memory\n");
  shmdt(sharedMemPtr);
  printf("Cleaning up shared memory\n");
  shmctl(shmid, IPC_RMID, NULL);
  printf("Cleaning up the message queue\n");
  msgctl(msqid, IPC_RMID, NULL);
}


x86 assembly (clang, -O0):
<cleanUp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <shmdt@plt>
lea    0xeb0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <shmctl@plt>
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <msgctl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanUp>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <shmdt@plt>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e6d(%rip),%rbx
mov    (%rbx),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1060 <shmctl@plt>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%esi
mov    %r14d,%edi
xor    %edx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <msgctl@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Detaching from shared memory\0A\00"
@.str.1 = [27 x i8] c"Cleaning up shared memory\0A\00"
@IPC_RMID = global i32 0
@.str.2 = [31 x i8] c"Cleaning up the message queue\0A\00"
define void @cleanUp(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %6
%9 = call i32 @shmdt(i8* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = load i32, i32* @IPC_RMID
%13 = call i32 @shmctl(i32 %11, i32 %12, i32* null)
%14 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* %5
%16 = load i32, i32* @IPC_RMID
%17 = call i32 @msgctl(i32 %15, i32 %16, i32* null)
ret void
}

LLVM IR (-O2):
@IPC_RMID = global i32 0
@str = [29 x i8] c"Detaching from shared memory\00"
@str.3 = [26 x i8] c"Cleaning up shared memory\00"
@str.4 = [30 x i8] c"Cleaning up the message queue\00"
define void @cleanUp(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @shmdt(i8* %2)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.3, i64 0, i64 0))
%7 = load i32, i32* @IPC_RMID
%8 = tail call i32 @shmctl(i32 %0, i32 %7, i32* null)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.4, i64 0, i64 0))
%10 = load i32, i32* @IPC_RMID
%11 = tail call i32 @msgctl(i32 %1, i32 %10, i32* null)
ret void
}