#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 /*<<< orphan*/ execlp(char *, char *, char *, char *, char *, char *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ system(char *);
int vfork();
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  pid_t pid = vfork();
  if (pid == -1) {
    perror("vfork");
    return 1;
  }
  if (pid) {
    waitpid(pid, &pid, 0);
    {
      size_t n = 0, i;
      char *stty = *(argv + 2);
      char *stty_cmd;
      while (*(stty + n++))
        ;
      stty_cmd = malloc((5 + n) * sizeof(char));
      for (i = 0; i < 5; i++)
        *(stty_cmd + i) = *("stty " + i);
      stty_cmd += 5;
      for (i = 0; i < n; i++)
        *(stty_cmd + i) = *(stty + i);
      stty_cmd -= 5;
      system(stty_cmd);
      free(stty_cmd);
    }
  } else
    execlp("setsid", "setsid", "-c", "cerberus", "--", *(argv + 1), NULL);
  return 0;
  (void)argc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
call   1080 <vfork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b0 <main+0x40>
lea    0xe61(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fb <main+0x18b>
cmpl   $0x0,-0x14(%rbp)
je     12be <main+0x14e>
mov    -0x14(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
cmpb   $0x0,(%rax,%rcx,1)
je     11fe <main+0x8e>
jmp    11dc <main+0x6c>
mov    -0x20(%rbp),%rax
add    $0x5,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x5,-0x28(%rbp)
jae    1252 <main+0xe2>
mov    -0x28(%rbp),%rcx
lea    0xdd3(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    121d <main+0xad>
mov    -0x38(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    129b <main+0x12b>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1266 <main+0xf6>
mov    -0x38(%rbp),%rax
add    $0xfffffffffffffffb,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <system@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    12f4 <main+0x184>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r9
lea    0xd3f(%rip),%rsi
lea    0xd3f(%rip),%rdx
lea    0xd3b(%rip),%rcx
lea    0xd3d(%rip),%r8
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   1090 <execlp@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
call   1090 <vfork@plt>
mov    %eax,0x14(%rsp)
test   %eax,%eax
je     120e <main+0x8e>
cmp    $0xffffffff,%eax
je     124d <main+0xcd>
mov    %eax,%edi
lea    0x14(%rsp),%rsi
xor    %ebp,%ebp
mov    %ebp,%edx
call   1070 <waitpid@plt>
mov    0x10(%rbx),%r14
mov    %ebp,%eax
nopl   0x0(%rax)
lea    0x1(%rax),%rbx
cmpb   $0x0,(%r14,%rax,1)
mov    %rbx,%rax
jne    11c0 <main+0x40>
mov    %ebx,%eax
lea    0x5(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
movl   $0x79747473,(%rax)
movb   $0x20,0x4(%rax)
test   %rbx,%rbx
je     11fc <main+0x7c>
mov    %rax,%rdi
add    $0x5,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
mov    %r15,%rdi
call   1040 <system@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1240 <main+0xc0>
mov    0x8(%rbx),%r9
mov    %rsp,%rax
movq   $0x0,(%rax)
lea    0xde9(%rip),%rdi
lea    0xde9(%rip),%rdx
lea    0xde5(%rip),%rcx
lea    0xde7(%rip),%r8
mov    %rdi,%rsi
call   10a0 <execlp@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdac(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    1242 <main+0xc2>

LLVM IR (-O0):
@.str = [6 x i8] c"vfork\00"
@.str.1 = [6 x i8] c"stty \00"
@.str.2 = [7 x i8] c"setsid\00"
@.str.3 = [3 x i8] c"-c\00"
@.str.4 = [9 x i8] c"cerberus\00"
@.str.5 = [3 x i8] c"--\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @vfork()
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %83
16: ; preds = %2
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %77
19: ; preds = %16
%20 = load i32, i32* %6
%21 = call i32 @waitpid(i32 %20, i32* %6, i32 0)
store i64 0, i64* %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
store i8* %24, i8** %9
br label %25
25: ; preds = %32, %19
%26 = load i8*, i8** %9
%27 = load i64, i64* %7
%28 = add i64 %27, 1
store i64 %28, i64* %7
%29 = getelementptr inbounds i8, i8* %26, i64 %27
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
br label %25
33: ; preds = %25
%34 = load i64, i64* %7
%35 = add i64 5, %34
%36 = mul i64 %35, 1
%37 = trunc i64 %36 to i32
%38 = call i8* @malloc(i32 %37)
store i8* %38, i8** %10
store i64 0, i64* %8
br label %39
39: ; preds = %49, %33
%40 = load i64, i64* %8
%41 = icmp ult i64 %40, 5
br i1 %41, label %42, label %52
42: ; preds = %39
%43 = load i64, i64* %8
%44 = getelementptr inbounds i8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %43
%45 = load i8, i8* %44
%46 = load i8*, i8** %10
%47 = load i64, i64* %8
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8 %45, i8* %48
br label %49
49: ; preds = %42
%50 = load i64, i64* %8
%51 = add i64 %50, 1
store i64 %51, i64* %8
br label %39
52: ; preds = %39
%53 = load i8*, i8** %10
%54 = getelementptr inbounds i8, i8* %53, i64 5
store i8* %54, i8** %10
store i64 0, i64* %8
br label %55
55: ; preds = %67, %52
%56 = load i64, i64* %8
%57 = load i64, i64* %7
%58 = icmp ult i64 %56, %57
br i1 %58, label %59, label %70
59: ; preds = %55
%60 = load i8*, i8** %9
%61 = load i64, i64* %8
%62 = getelementptr inbounds i8, i8* %60, i64 %61
%63 = load i8, i8* %62
%64 = load i8*, i8** %10
%65 = load i64, i64* %8
%66 = getelementptr inbounds i8, i8* %64, i64 %65
store i8 %63, i8* %66
br label %67
67: ; preds = %59
%68 = load i64, i64* %8
%69 = add i64 %68, 1
store i64 %69, i64* %8
br label %55
70: ; preds = %55
%71 = load i8*, i8** %10
%72 = getelementptr inbounds i8, i8* %71, i64 -5
store i8* %72, i8** %10
%73 = load i8*, i8** %10
%74 = call i32 @system(i8* %73)
%75 = load i8*, i8** %10
%76 = call i32 @free(i8* %75)
br label %82
77: ; preds = %16
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = call i32 @execlp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %80, i32* null)
br label %82
82: ; preds = %77, %70
store i32 0, i32* %3
br label %83
83: ; preds = %82, %14
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [6 x i8] c"vfork\00"
@.str.1 = [6 x i8] c"stty \00"
@.str.2 = [7 x i8] c"setsid\00"
@.str.3 = [3 x i8] c"-c\00"
@.str.4 = [9 x i8] c"cerberus\00"
@.str.5 = [3 x i8] c"--\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @vfork()
store i32 %5, i32* %3
switch i32 %5, label %8 [
i32 -1, label %6
i32 0, label %28
]
6: ; preds = %2
%7 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %32
8: ; preds = %2
%9 = call i32 @waitpid(i32 %5, i32* %3, i32 0)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
br label %12
12: ; preds = %12, %8
%13 = phi i64 [ 0, %8 ], [ %14, %12 ]
%14 = add i64 %13, 1
%15 = getelementptr inbounds i8, i8* %11, i64 %13
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %12
18: ; preds = %12
%19 = trunc i64 %13 to i32
%20 = add i32 %19, 6
%21 = call i8* @malloc(i32 %20)
%22 = icmp eq i64 %14, 0
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = getelementptr i8, i8* %21, i64 5
br label %25
25: ; preds = %23, %18
%26 = call i32 @system(i8* %21)
%27 = call i32 @free(i8* %21)
br label %32
28: ; preds = %2
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @execlp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %30, i32* null)
br label %32
32: ; preds = %25, %28, %6
%33 = phi i32 [ 1, %6 ], [ 0, %28 ], [ 0, %25 ]
ret i32 %33
}