#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getpgrp();
scalar_t__ getpid();
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printf(char *);
int setsid();
int /*<<< orphan*/ stderr;
int main() {
  if (getpid() != getpgrp()) {
    fprintf(stderr, "This program can only be run as the process "
                    "group leader. Exiting\n");
    exit(EXIT_FAILURE);
  }
  if (setsid() == -1)
    pexit("setsid");
  printf("setsid(2) succeeded. Your kernel has a bug\n");
  exit(EXIT_FAILURE);
}


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    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <getpgrp@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
cmp    %rcx,%rax
je     11c4 <main+0x54>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1050 <setsid@plt>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x70>
lea    0xe68(%rip),%rdi
call   1090 <pexit@plt>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <getpgrp@plt>
cmp    %rax,%rbx
jne    11ad <main+0x3d>
xor    %eax,%eax
call   1050 <setsid@plt>
cmp    $0xffffffff,%eax
jne    119f <main+0x2f>
lea    0xea9(%rip),%rdi
call   1090 <pexit@plt>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
jmp    11c2 <main+0x52>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [67 x i8] c"This program can only be run as the process group leader. Exiting\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"setsid\00"
@.str.2 = [44 x i8] c"setsid(2) succeeded. Your kernel has a bug\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i64 (...) @getpid()
%3 = call i64 (...) @getpgrp()
%4 = icmp ne i64 %2, %3
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = call i32 (...) @setsid()
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [67 x i8] c"This program can only be run as the process group leader. Exiting\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"setsid\00"
@str = [43 x i8] c"setsid(2) succeeded. Your kernel has a bug\00"
define i32 @main() {
%1 = tail call i64 (...) @getpid()
%2 = tail call i64 (...) @getpgrp()
%3 = icmp eq i64 %1, %2
br i1 %3, label %9, label %4
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = tail call i32 (...) @setsid()
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
}