#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 key_t;

/* Variables and functions */
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ftok(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ semctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int semget(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int shmget(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  key_t key;
  int sem;
  int shm;
  if (argc != 2) {
    fprintf(stderr, "Syntaxe : %s fichier_clé \n", argv[0]);
    exit(1);
  }
  if ((key = ftok(argv[1], 0)) == -1) {
    perror("ftok");
    exit(1);
  }
  if (((sem = semget(key, 1, 0)) == -1) ||
      ((shm = shmget(key, 256, 0)) == -1)) {
    perror("semget/shmget");
    exit(1);
  }
  shmctl(shm, IPC_RMID, NULL);
  semctl(sem, IPC_RMID, 0);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c6 <main+0x46>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
call   10a0 <ftok@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f7 <main+0x77>
lea    0xe34(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <semget@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     122d <main+0xad>
mov    -0x14(%rbp),%edi
mov    $0x100,%esi
xor    %edx,%edx
call   1080 <shmget@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1243 <main+0xc3>
lea    0xded(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <shmctl@plt>
mov    -0x18(%rbp),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <semctl@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11f3 <main+0x73>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
call   10a0 <ftok@plt>
cmp    $0xffffffff,%eax
je     1215 <main+0x95>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <semget@plt>
cmp    $0xffffffff,%eax
je     11ea <main+0x6a>
mov    %eax,%ebx
mov    %ebp,%edi
mov    $0x100,%esi
xor    %edx,%edx
call   1080 <shmget@plt>
cmp    $0xffffffff,%eax
je     11ea <main+0x6a>
mov    0x2e0f(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <shmctl@plt>
mov    0x0(%rbp),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1070 <semctl@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe30(%rip),%rdi
jmp    121c <main+0x9c>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdfa(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe00(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Syntaxe : %s fichier_cl\C3\A9 \0A\00"
@.str.1 = [5 x i8] c"ftok\00"
@.str.2 = [14 x i8] c"semget/shmget\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @ftok(i8* %21, i32 0)
store i32 %22, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = load i32, i32* %6
%29 = call i32 @semget(i32 %28, i32 1, i32 0)
store i32 %29, i32* %7
%30 = icmp eq i32 %29, -1
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i32, i32* %6
%33 = call i32 @shmget(i32 %32, i32 256, i32 0)
store i32 %33, i32* %8
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %31, %27
%36 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = load i32, i32* %8
%40 = load i32, i32* @IPC_RMID
%41 = call i32 @shmctl(i32 %39, i32 %40, i32* null)
%42 = load i32, i32* %7
%43 = load i32, i32* @IPC_RMID
%44 = call i32 @semctl(i32 %42, i32 %43, i32 0)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Syntaxe : %s fichier_cl\C3\A9 \0A\00"
@.str.1 = [5 x i8] c"ftok\00"
@.str.2 = [14 x i8] c"semget/shmget\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @ftok(i8* %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = tail call i32 @semget(i32 %12, i32 1, i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = tail call i32 @shmget(i32 %12, i32 256, i32 0)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %20, %17
%24 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = load i32, i32* @IPC_RMID
%28 = tail call i32 @shmctl(i32 %21, i32 %27, i32* null)
%29 = load i32, i32* @IPC_RMID
%30 = tail call i32 @semctl(i32 %18, i32 %29, i32 0)
ret i32 0
}