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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getpid();
int getsid(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int setsid();
int main() {
  pid_t SID;
  printf("SID avant la creation de la session : %d \n", getsid(getpid()));
  SID = setsid();
  if (SID == -1) {
    perror("Erreur lors de la creation de la nouvelle session.");
    exit(-1);
  }
  printf("SID apres la creation de la session : %d \n", getsid(getpid()));
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <getsid@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <setsid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b5 <main+0x55>
lea    0xe85(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <getsid@plt>
mov    %eax,%esi
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <getsid@plt>
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <setsid@plt>
cmp    $0xffffffff,%eax
je     11b0 <main+0x50>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <getsid@plt>
lea    0xec0(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xe74(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"SID avant la creation de la session : %d \0A\00"
@.str.1 = [51 x i8] c"Erreur lors de la creation de la nouvelle session.\00"
@.str.2 = [43 x i8] c"SID apres la creation de la session : %d \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @getpid()
%4 = call i32 @getsid(i32 %3)
%5 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 (...) @setsid()
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = call i32 (...) @getpid()
%14 = call i32 @getsid(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}

LLVM IR (-O2):
@.str = [43 x i8] c"SID avant la creation de la session : %d \0A\00"
@.str.1 = [51 x i8] c"Erreur lors de la creation de la nouvelle session.\00"
@.str.2 = [43 x i8] c"SID apres la creation de la session : %d \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 @getsid(i32 %1)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i32 (...) @setsid()
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 @getsid(i32 %10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_SUCCESS
ret i32 %13
}