#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 IPC_CREAT;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int ftok(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
char *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  key_t key;
  int shm;
  char *chaine = NULL;
  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 ((shm = shmget(key, 256, IPC_CREAT | 0600)) == -1) {
    perror("shmget");
    exit(1);
  }
  if ((chaine = shmat(shm, NULL, 0)) == NULL) {
    perror("shmat");
    exit(1);
  }
  fprintf(stdout, "> ");
  fgets(chaine, 256, stdin);
  printf("%p", chaine);
  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)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d0 <main+0x50>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1050 <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    1201 <main+0x81>
lea    0xe2a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
or     $0x180,%edx
mov    $0x100,%esi
call   1080 <shmget@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    123f <main+0xbf>
lea    0xdf1(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1271 <main+0xf1>
lea    0xdc6(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d55(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1040 <fgets@plt>
mov    -0x20(%rbp),%rsi
lea    0xd87(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    1214 <main+0x94>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
call   10a0 <ftok@plt>
cmp    $0xffffffff,%eax
je     1238 <main+0xb8>
mov    0x2e23(%rip),%rcx
mov    $0x180,%edx
or     (%rcx),%edx
mov    %eax,%edi
mov    $0x100,%esi
call   1080 <shmget@plt>
cmp    $0xffffffff,%eax
je     1241 <main+0xc1>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
test   %rax,%rax
je     124a <main+0xca>
mov    %rax,%rbx
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
lea    0xe29(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdd9(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xddd(%rip),%rdi
jmp    1251 <main+0xd1>
lea    0xdd9(%rip),%rdi
jmp    1251 <main+0xd1>
lea    0xdd7(%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"
@IPC_CREAT = global i32 0
@.str.2 = [7 x i8] c"shmget\00"
@.str.3 = [6 x i8] c"shmat\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.5 = [3 x i8] c"%p\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
%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 (i32, i8*, ...) @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 = load i32, i32* @IPC_CREAT
%30 = or i32 %29, 384
%31 = call i32 @shmget(i32 %28, i32 256, i32 %30)
store i32 %31, i32* %7
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %27
%37 = load i32, i32* %7
%38 = call i8* @shmat(i32 %37, i32* null, i32 0)
store i8* %38, i8** %8
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %36
%44 = load i32, i32* @stdout
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%46 = load i8*, i8** %8
%47 = load i32, i32* @stdin
%48 = call i32 @fgets(i8* %46, i32 256, i32 %47)
%49 = load i8*, i8** %8
%50 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %49)
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"
@IPC_CREAT = global i32 0
@.str.2 = [7 x i8] c"shmget\00"
@.str.3 = [6 x i8] c"shmat\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.5 = [3 x i8] c"%p\00"
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 (i32, i8*, ...) @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 = load i32, i32* @IPC_CREAT
%19 = or i32 %18, 384
%20 = tail call i32 @shmget(i32 %12, i32 256, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = tail call i8* @shmat(i32 %20, i32* null, i32 0)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %25
%32 = load i32, i32* @stdout
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* @stdin
%35 = tail call i32 @fgets(i8* %26, i32 256, i32 %34)
%36 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %26)
ret i32 0
}