#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*/ PR_SET_PTRACER;
int /*<<< orphan*/ PR_SET_PTRACER_ANY;
int SIGABRT;
int SIGSEGV;
int /*<<< orphan*/ SIGSTOP;
int /*<<< orphan*/ execlp(char *, char *, char *, char *, char *);
int fork();
int getppid();
int /*<<< orphan*/ prctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ raise(int /*<<< orphan*/);
void gdb(int sig) {
  if (sig == SIGSEGV || sig == SIGABRT) {
    pid_t cpid = fork();
    if (cpid == -1)
      return;
    else if (cpid != 0) {
      prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0);
      raise(SIGSTOP);
    } else {
      char cmd[100];
      const char *stem = "gdb _dummy_process_name_                   ";
      const char *s = stem;
      char *d = cmd;
      while (*s) {
        *d++ = *s++;
      }
      *d-- = '\0';
      char *hexppid = d;
      pid_t ppid = getppid();
      while (ppid) {
        *hexppid = ((ppid & 0xF) + '0');
        if (*hexppid > '9')
          *hexppid += 'a' - '0' - 10;
        --hexppid;
        ppid >>= 4;
      }
      *hexppid-- = 'x';
      *hexppid = '0';
      execlp("mate-terminal", "mate-terminal", "-e", cmd, (char *)NULL);
    }
  }
}


x86 assembly (clang, -O0):
<gdb>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%eax
je     1182 <gdb+0x32>
mov    -0x4(%rbp),%eax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%eax
jne    131a <gdb+0x1ca>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    119b <gdb+0x4b>
jmp    131a <gdb+0x1ca>
cmpl   $0x0,-0x8(%rbp)
je     11d8 <gdb+0x88>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1040 <prctl@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
jmp    1310 <gdb+0x1c0>
lea    0xe21(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x80(%rbp),%rax
cmpb   $0x0,(%rax)
je     1230 <gdb+0xe0>
mov    -0x80(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x80(%rbp)
mov    (%rax),%cl
mov    -0x88(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x88(%rbp)
mov    %cl,(%rax)
jmp    11f6 <gdb+0xa6>
mov    -0x88(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x88(%rbp)
movb   $0x0,(%rax)
mov    -0x88(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
je     12cf <gdb+0x17f>
mov    -0x94(%rbp),%eax
and    $0xf,%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x90(%rbp),%rax
mov    %cl,(%rax)
mov    -0x90(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    12a9 <gdb+0x159>
mov    -0x90(%rbp),%rax
movsbl (%rax),%ecx
add    $0x27,%ecx
mov    %cl,(%rax)
mov    -0x90(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x90(%rbp)
mov    -0x94(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x94(%rbp)
jmp    1263 <gdb+0x113>
mov    -0x90(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x90(%rbp)
movb   $0x78,(%rax)
mov    -0x90(%rbp),%rax
movb   $0x30,(%rax)
lea    -0x70(%rbp),%rcx
lea    0xd30(%rip),%rsi
lea    0xd37(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1060 <execlp@plt>
jmp    1315 <gdb+0x1c5>
jmp    131a <gdb+0x1ca>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdb>:
push   %rbx
sub    $0x70,%rsp
mov    0x2e8c(%rip),%rax
cmp    %edi,(%rax)
je     116f <gdb+0x1f>
mov    0x2e61(%rip),%rax
cmp    %edi,(%rax)
jne    1259 <gdb+0x109>
xor    %eax,%eax
call   1070 <fork@plt>
cmp    $0xffffffff,%eax
je     1259 <gdb+0x109>
test   %eax,%eax
jne    1200 <gdb+0xb0>
movaps 0xe76(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x5f656d616e5f7373,%rax
6d 65 5f
mov    %rax,0x10(%rsp)
lea    0x2a(%rsp),%rbx
movaps 0xe67(%rip),%xmm0
movups %xmm0,0x18(%rsp)
movl   $0x20202020,0x27(%rsp)
20
movb   $0x0,0x2b(%rsp)
xor    %eax,%eax
call   1050 <getppid@plt>
test   %eax,%eax
je     1231 <gdb+0xe1>
mov    %eax,%ecx
nopl   0x0(%rax,%rax,1)
mov    %eax,%edx
and    $0xf,%dl
lea    0x30(%rdx),%esi
add    $0x57,%dl
cmp    $0x3a,%sil
movzbl %dl,%edx
movzbl %sil,%esi
cmovae %edx,%esi
mov    %sil,(%rbx)
sar    $0x4,%ecx
add    $0xffffffffffffffff,%rbx
cmp    $0xf,%eax
mov    %ecx,%eax
ja     11d0 <gdb+0x80>
lea    0x1(%rbx),%rax
jmp    1236 <gdb+0xe6>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <prctl@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
add    $0x70,%rsp
pop    %rbx
jmp    1030 <raise@plt>
lea    0x2b(%rsp),%rax
movb   $0x78,(%rbx)
movb   $0x30,-0x2(%rax)
lea    0xddc(%rip),%rdi
lea    0xde3(%rip),%rdx
mov    %rsp,%rcx
mov    %rdi,%rsi
xor    %r8d,%r8d
call   1060 <execlp@plt>
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SIGSEGV = global i32 0
@SIGABRT = global i32 0
@PR_SET_PTRACER = global i32 0
@PR_SET_PTRACER_ANY = global i32 0
@SIGSTOP = global i32 0
@.str = [44 x i8] c"gdb _dummy_process_name_ \00"
@.str.1 = [14 x i8] c"mate-terminal\00"
@.str.2 = [3 x i8] c"-e\00"
define void @gdb(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %2
%10 = load i32, i32* %2
%11 = load i32, i32* @SIGSEGV
%12 = icmp eq i32 %10, %11
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = load i32, i32* %2
%15 = load i32, i32* @SIGABRT
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %81
17: ; preds = %13, %1
%18 = call i32 (...) @fork()
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %17
br label %81
22: ; preds = %17
%23 = load i32, i32* %3
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* @PR_SET_PTRACER
%27 = load i32, i32* @PR_SET_PTRACER_ANY
%28 = call i32 @prctl(i32 %26, i32 %27, i32 0, i32 0, i32 0)
%29 = load i32, i32* @SIGSTOP
%30 = call i32 @raise(i32 %29)
br label %79
31: ; preds = %22
store i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8** %5
%32 = load i8*, i8** %5
store i8* %32, i8** %6
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
store i8* %33, i8** %7
br label %34
34: ; preds = %38, %31
%35 = load i8*, i8** %6
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %6
%41 = load i8, i8* %39
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %7
store i8 %41, i8* %42
br label %34
44: ; preds = %34
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i32 -1
store i8* %46, i8** %7
store i8 0, i8* %45
%47 = load i8*, i8** %7
store i8* %47, i8** %8
%48 = call i32 (...) @getppid()
store i32 %48, i32* %9
br label %49
49: ; preds = %68, %44
%50 = load i32, i32* %9
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %73
52: ; preds = %49
%53 = load i32, i32* %9
%54 = and i32 %53, 15
%55 = add nsw i32 %54, 48
%56 = trunc i32 %55 to i8
%57 = load i8*, i8** %8
store i8 %56, i8* %57
%58 = load i8*, i8** %8
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp sgt i32 %60, 57
br i1 %61, label %62, label %68
62: ; preds = %52
%63 = load i8*, i8** %8
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = add nsw i32 %65, 39
%67 = trunc i32 %66 to i8
store i8 %67, i8* %63
br label %68
68: ; preds = %62, %52
%69 = load i8*, i8** %8
%70 = getelementptr inbounds i8, i8* %69, i32 -1
store i8* %70, i8** %8
%71 = load i32, i32* %9
%72 = ashr i32 %71, 4
store i32 %72, i32* %9
br label %49
73: ; preds = %49
%74 = load i8*, i8** %8
%75 = getelementptr inbounds i8, i8* %74, i32 -1
store i8* %75, i8** %8
store i8 120, i8* %74
%76 = load i8*, i8** %8
store i8 48, i8* %76
%77 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%78 = call i32 @execlp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %77, i8* null)
br label %79
79: ; preds = %73, %25
br label %80
80: ; preds = %79
br label %81
81: ; preds = %21, %80, %13
ret void
}

LLVM IR (-O2):
@SIGSEGV = global i32 0
@SIGABRT = global i32 0
@PR_SET_PTRACER = global i32 0
@PR_SET_PTRACER_ANY = global i32 0
@SIGSTOP = global i32 0
@.str.1 = [14 x i8] c"mate-terminal\00"
@.str.2 = [3 x i8] c"-e\00"
define void @gdb(i32 %0) {
%2 = alloca [100 x i8]
%3 = load i32, i32* @SIGSEGV
%4 = icmp eq i32 %3, %0
%5 = load i32, i32* @SIGABRT
%6 = icmp eq i32 %5, %0
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %8, label %49
8: ; preds = %1
%9 = tail call i32 (...) @fork()
switch i32 %9, label %10 [
i32 -1, label %49
i32 0, label %16
]
10: ; preds = %8
%11 = load i32, i32* @PR_SET_PTRACER
%12 = load i32, i32* @PR_SET_PTRACER_ANY
%13 = tail call i32 @prctl(i32 %11, i32 %12, i32 0, i32 0, i32 0)
%14 = load i32, i32* @SIGSTOP
%15 = tail call i32 @raise(i32 %14)
br label %49
16: ; preds = %8
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 16
%19 = bitcast [100 x i8]* %2 to <16 x i8>*
store <16 x i8> <i8 103, i8 100, i8 98, i8 32, i8 95, i8 100, i8 117, i8 109, i8 109, i8 121, i8 95, i8 112, i8 114, i8 111, i8 99, i8 101>, <16 x i8>* %19
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 17
store i8 115, i8* %18
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 18
store i8 115, i8* %20
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 19
store i8 95, i8* %21
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 20
store i8 110, i8* %22
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 21
store i8 97, i8* %23
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 22
store i8 109, i8* %24
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 23
store i8 101, i8* %25
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 24
store i8 95, i8* %26
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 42
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 43
store i8 0, i8* %29
%30 = tail call i32 (...) @getppid()
%31 = icmp eq i32 %30, 0
br i1 %31, label %44, label %32
32: ; preds = %16, %32
%33 = phi i8* [ %42, %32 ], [ %28, %16 ]
%34 = phi i32 [ %41, %32 ], [ %30, %16 ]
%35 = trunc i32 %34 to i8
%36 = and i8 %35, 15
%37 = or i8 %36, 48
%38 = icmp ugt i8 %37, 57
%39 = add nuw nsw i8 %36, 87
%40 = select i1 %38, i8 %39, i8 %37
store i8 %40, i8* %33
%41 = ashr i32 %34, 4
%42 = getelementptr inbounds i8, i8* %33, i64 -1
%43 = icmp ult i32 %34, 16
br i1 %43, label %44, label %32
44: ; preds = %32, %16
%45 = phi i8* [ %29, %16 ], [ %33, %32 ]
%46 = phi i8* [ %28, %16 ], [ %42, %32 ]
%47 = getelementptr inbounds i8, i8* %45, i64 -2
store i8 120, i8* %46
store i8 48, i8* %47
%48 = call i32 @execlp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %17, i8* null)
br label %49
49: ; preds = %8, %10, %44, %1
ret void
}