#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 */
scalar_t__ SIGABRT;
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WTERMSIG(int);
int _error(char const *, char *, int);
int _ssp_child(char const *, unsigned int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *,
                           scalar_t__);
int /*<<< orphan*/ stderr;
int waitpid(int, int *, int /*<<< orphan*/);
int _ssp(char const *progname, unsigned int pattern) {
  pid_t pid;
  int status;
  if ((pid = fork()) == -1)
    return -_error(progname, "fork", 1);
  if (pid == 0)
    return -_ssp_child(progname, pattern);
  while (waitpid(pid, &status, 0) != -1)
    if (WIFEXITED(status)) {
      fprintf(stderr, "%s: %s%d\n", progname, "Terminated with error code ",
              WEXITSTATUS(status));
      return -1;
    } else if (WIFSIGNALED(status)) {
      if (WTERMSIG(status) == SIGABRT)
        return 0;
      fprintf(stderr, "%s: %s%d\n", progname, "Terminated with signal ",
              WTERMSIG(status));
      return -1;
    }
  return -_error(progname, "waitpid", 1);
}


x86 assembly (clang, -O0):
<_ssp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11d5 <_ssp+0x45>
mov    -0x10(%rbp),%rdi
lea    0xe43(%rip),%rsi
mov    $0x1,%edx
call   1050 <_error@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    130f <_ssp+0x17f>
cmpl   $0x0,-0x18(%rbp)
jne    11f9 <_ssp+0x69>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1090 <_ssp_child@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    130f <_ssp+0x17f>
jmp    11fe <_ssp+0x6e>
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0xffffffff,%eax
je     12f1 <_ssp+0x161>
mov    -0x1c(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     126c <_ssp+0xdc>
mov    0x2db2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%r8
lea    0xdb1(%rip),%rsi
lea    0xdb4(%rip),%rcx
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130f <_ssp+0x17f>
mov    -0x1c(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     12e7 <_ssp+0x157>
mov    -0x1c(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    0x2d4b(%rip),%rcx
cmp    (%rcx),%rax
jne    12a2 <_ssp+0x112>
movl   $0x0,-0x4(%rbp)
jmp    130f <_ssp+0x17f>
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%r8
lea    0xd36(%rip),%rsi
lea    0xd55(%rip),%rcx
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130f <_ssp+0x17f>
jmp    12ec <_ssp+0x15c>
jmp    11fe <_ssp+0x6e>
mov    -0x10(%rbp),%rdi
lea    0xd47(%rip),%rsi
mov    $0x1,%edx
call   1050 <_error@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ssp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
xor    %eax,%eax
call   10b0 <fork@plt>
cmp    $0xffffffff,%eax
je     11be <_ssp+0x2e>
mov    %eax,%ebp
test   %eax,%eax
jne    11c7 <_ssp+0x37>
mov    %r14,%rdi
mov    %ebx,%esi
call   1090 <_ssp_child@plt>
jmp    124d <_ssp+0xbd>
lea    0xe3b(%rip),%rsi
jmp    1240 <_ssp+0xb0>
lea    0xc(%rsp),%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0xffffffff,%eax
je     1239 <_ssp+0xa9>
mov    0xc(%rsp),%edi
call   10a0 <WIFEXITED@plt>
test   %rax,%rax
jne    1258 <_ssp+0xc8>
mov    0xc(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
je     11d0 <_ssp+0x40>
mov    0xc(%rsp),%edi
call   1060 <WTERMSIG@plt>
mov    %rax,%rcx
mov    0x2dc8(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     124f <_ssp+0xbf>
mov    0x2dc2(%rip),%rax
mov    (%rax),%ebx
mov    0xc(%rsp),%edi
call   1060 <WTERMSIG@plt>
lea    0xdd5(%rip),%rsi
lea    0xdf4(%rip),%rcx
jmp    1278 <_ssp+0xe8>
lea    0xe03(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1050 <_error@plt>
neg    %eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d81(%rip),%rax
mov    (%rax),%ebx
mov    0xc(%rsp),%edi
call   1070 <WEXITSTATUS@plt>
lea    0xd94(%rip),%rsi
lea    0xd97(%rip),%rcx
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    124f <_ssp+0xbf>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"%s: %s%d\0A\00"
@.str.2 = [28 x i8] c"Terminated with error code \00"
@SIGABRT = global i64 0
@.str.3 = [24 x i8] c"Terminated with signal \00"
@.str.4 = [8 x i8] c"waitpid\00"
define i32 @_ssp(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = call i32 (...) @fork()
store i32 %8, i32* %6
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @_error(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
%13 = sub nsw i32 0, %12
store i32 %13, i32* %3
br label %59
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = call i32 @_ssp_child(i8* %18, i32 %19)
%21 = sub nsw i32 0, %20
store i32 %21, i32* %3
br label %59
22: ; preds = %14
br label %23
23: ; preds = %54, %22
%24 = load i32, i32* %6
%25 = call i32 @waitpid(i32 %24, i32* %7, i32 0)
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %55
27: ; preds = %23
%28 = load i32, i32* %7
%29 = call i64 @WIFEXITED(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %4
%34 = load i32, i32* %7
%35 = call i64 @WEXITSTATUS(i32 %34)
%36 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %35)
store i32 -1, i32* %3
br label %59
37: ; preds = %27
%38 = load i32, i32* %7
%39 = call i64 @WIFSIGNALED(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = load i32, i32* %7
%43 = call i64 @WTERMSIG(i32 %42)
%44 = load i64, i64* @SIGABRT
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %41
store i32 0, i32* %3
br label %59
47: ; preds = %41
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %4
%50 = load i32, i32* %7
%51 = call i64 @WTERMSIG(i32 %50)
%52 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %49, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %51)
store i32 -1, i32* %3
br label %59
53: ; preds = %37
br label %54
54: ; preds = %53
br label %23
55: ; preds = %23
%56 = load i8*, i8** %4
%57 = call i32 @_error(i8* %56, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 1)
%58 = sub nsw i32 0, %57
store i32 %58, i32* %3
br label %59
59: ; preds = %55, %47, %46, %31, %17, %10
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"%s: %s%d\0A\00"
@.str.2 = [28 x i8] c"Terminated with error code \00"
@SIGABRT = global i64 0
@.str.3 = [24 x i8] c"Terminated with signal \00"
@.str.4 = [8 x i8] c"waitpid\00"
define i32 @_ssp(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (...) @fork()
switch i32 %5, label %12 [
i32 -1, label %6
i32 0, label %9
]
6: ; preds = %2
%7 = tail call i32 @_error(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
%8 = sub nsw i32 0, %7
br label %41
9: ; preds = %2
%10 = tail call i32 @_ssp_child(i8* %0, i32 %1)
%11 = sub nsw i32 0, %10
br label %41
12: ; preds = %2, %24
%13 = call i32 @waitpid(i32 %5, i32* %3, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %38, label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = call i64 @WIFEXITED(i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i32, i32* %3
%22 = call i64 @WEXITSTATUS(i32 %21)
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %22)
br label %41
24: ; preds = %15
%25 = load i32, i32* %3
%26 = call i64 @WIFSIGNALED(i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %12, label %28
28: ; preds = %24
%29 = load i32, i32* %3
%30 = call i64 @WTERMSIG(i32 %29)
%31 = load i64, i64* @SIGABRT
%32 = icmp eq i64 %30, %31
br i1 %32, label %41, label %33
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i32, i32* %3
%36 = call i64 @WTERMSIG(i32 %35)
%37 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %36)
br label %41
38: ; preds = %12
%39 = call i32 @_error(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 1)
%40 = sub nsw i32 0, %39
br label %41
41: ; preds = %28, %38, %33, %19, %9, %6
%42 = phi i32 [ %8, %6 ], [ %11, %9 ], [ -1, %19 ], [ -1, %33 ], [ %40, %38 ], [ 0, %28 ]
ret i32 %42
}