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

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ execlp(char *, char *, char *, char *, char *, char *,
                          char *, ...);
long fork();
char *getenv(char *);
long getpid();
int /*<<< orphan*/ kill(long, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setpgid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
long waitpid(long, int *, int /*<<< orphan*/);
void startgdb(void) {
  char *env;
  char srcpath[1024];
  char pid[20];
  static long dpid = 0;
  char buf[4096];
  if (dpid) {
    int status;
    pid_t wpid = waitpid(dpid, &status, WNOHANG);
    if (wpid != dpid && !kill(dpid, 0))
      return;
  }
  sprintf(pid, "%ld", (long)getpid());
  if ((env = getenv("GDEBUG")))
    sprintf(srcpath, "%s", env);
  else
    sprintf(srcpath, ".");
  if (!(env = getenv("DISPLAY"))) {
    long child;
    child = fork();
    if (!child) {
      dpid = getpid();
      setpgid(0, 0);
    } else {
      sprintf(pid, "%ld", child);
      sleep(1);
      execlp("gdb", "gdb", "-dir", srcpath, "/dev/null", pid, NULL);
      perror("Error attaching gdb");
      kill(child, SIGKILL);
      return;
    }
  } else {
    dpid = fork();
    if (!dpid) {
      char geometry[20];
      setpgid(0, 0);
      sprintf(buf, "exec gdb -dir '%s' '%s' %s", srcpath, "/dev/null", pid);
      if ((env = getenv("GDB_GEOMETRY"))) {
        sprintf(geometry, "%s", env);
        execlp("xterm", "xterm ", "-title", "gdb", "-geometry", geometry, "-sb",
               "-sl", "2012", "-fn", "10x20", "-e", "sh", "-c", buf, NULL);
      } else {
        execlp("xterm", "xterm ", "-title", "gdb", "-sb", "-sl", "2012", "-fn",
               "10x20", "-e", "sh", "-c", buf, NULL);
        perror("Error attaching xterm/gdb");
        _exit(1);
      }
    }
  }
  sleep(10);
}


x86 assembly (clang, -O0):
<startgdb>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x14c8,%rsp
cmpq   $0x0,0x2eb4(%rip)
je     122a <startgdb+0x7a>
mov    0x2ea7(%rip),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
lea    -0x1454(%rbp),%rsi
call   1070 <waitpid@plt>
mov    %rax,-0x1460(%rbp)
mov    -0x1460(%rbp),%rax
cmp    0x2e7d(%rip),%rax
je     1225 <startgdb+0x75>
mov    0x2e70(%rip),%rdi
xor    %esi,%esi
call   1060 <kill@plt>
cmp    $0x0,%eax
jne    1225 <startgdb+0x75>
jmp    1582 <startgdb+0x3d2>
jmp    122a <startgdb+0x7a>
lea    -0x450(%rbp),%rax
mov    %rax,-0x1488(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x1488(%rbp),%rdi
mov    %rax,%rdx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    0xda6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     128f <startgdb+0xdf>
lea    -0x430(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    12a4 <startgdb+0xf4>
lea    -0x430(%rbp),%rdi
lea    0xd6e(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    0xd62(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    137e <startgdb+0x1ce>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x1468(%rbp)
cmpq   $0x0,-0x1468(%rbp)
jne    12f6 <startgdb+0x146>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %rax,0x2d98(%rip)
xor    %esi,%esi
mov    %esi,%edi
call   1090 <setpgid@plt>
jmp    1379 <startgdb+0x1c9>
lea    -0x450(%rbp),%rdi
mov    -0x1468(%rbp),%rdx
lea    0xcf5(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
lea    -0x430(%rbp),%rcx
lea    -0x450(%rbp),%r9
lea    0xd03(%rip),%rsi
lea    0xcdd(%rip),%rdx
lea    0xcdb(%rip),%r8
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
mov    $0x0,%al
call   10b0 <execlp@plt>
lea    0xcca(%rip),%rdi
call   1080 <perror@plt>
mov    -0x1468(%rbp),%rdi
mov    0x2c6b(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    1582 <startgdb+0x3d2>
jmp    1578 <startgdb+0x3c8>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,0x2cf4(%rip)
cmpq   $0x0,0x2cec(%rip)
jne    1573 <startgdb+0x3c3>
xor    %esi,%esi
mov    %esi,%edi
call   1090 <setpgid@plt>
lea    -0x1450(%rbp),%rdi
lea    -0x430(%rbp),%rdx
lea    -0x450(%rbp),%r8
lea    0xc79(%rip),%rsi
lea    0xc54(%rip),%rcx
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    0xc7f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     14c8 <startgdb+0x318>
lea    -0x1480(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xc57(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x1480(%rbp),%r9
lea    -0x1450(%rbp),%rax
mov    %rax,-0x1490(%rbp)
lea    0xc44(%rip),%rdi
lea    0xc43(%rip),%rsi
lea    0xc43(%rip),%rdx
lea    0xc03(%rip),%rcx
lea    0xc3c(%rip),%r8
lea    0xc3f(%rip),%rax
mov    %rax,-0x1498(%rbp)
lea    0xc35(%rip),%r13
lea    0xc32(%rip),%r12
lea    0xc30(%rip),%r15
lea    0xc2d(%rip),%r14
lea    0xc2c(%rip),%rbx
lea    0xc28(%rip),%r11
lea    0xc24(%rip),%r10
xor    %eax,%eax
mov    -0x1498(%rbp),%rax
mov    %rax,(%rsp)
mov    -0x1490(%rbp),%rax
mov    %r13,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    %r15,0x18(%rsp)
mov    %r14,0x20(%rsp)
mov    %rbx,0x28(%rsp)
mov    %r11,0x30(%rsp)
mov    %r10,0x38(%rsp)
mov    %rax,0x40(%rsp)
movq   $0x0,0x48(%rsp)
mov    $0x0,%al
call   10b0 <execlp@plt>
jmp    156e <startgdb+0x3be>
lea    -0x1450(%rbp),%rax
lea    0xb8a(%rip),%rdi
lea    0xb89(%rip),%rsi
lea    0xb89(%rip),%rdx
lea    0xb49(%rip),%rcx
lea    0xb8c(%rip),%r8
lea    0xb89(%rip),%r9
lea    0xb86(%rip),%r12
lea    0xb84(%rip),%r15
lea    0xb81(%rip),%r14
lea    0xb80(%rip),%rbx
lea    0xb7c(%rip),%r11
lea    0xb78(%rip),%r10
xor    %r13d,%r13d
mov    %r12,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
movq   $0x0,0x38(%rsp)
mov    $0x0,%al
call   10b0 <execlp@plt>
lea    0xb3f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
jmp    1573 <startgdb+0x3c3>
jmp    1578 <startgdb+0x3c8>
mov    $0xa,%edi
call   10c0 <sleep@plt>
add    $0x14c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<startgdb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1448,%rsp
mov    0x2eb0(%rip),%rdi
test   %rdi,%rdi
je     120e <startgdb+0x4e>
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
lea    0x440(%rsp),%rsi
call   1080 <waitpid@plt>
mov    0x2e8e(%rip),%rdi
cmp    %rdi,%rax
je     120e <startgdb+0x4e>
xor    %esi,%esi
call   1070 <kill@plt>
test   %eax,%eax
je     137f <startgdb+0x1bf>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xde4(%rip),%rsi
mov    %rsp,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xdd4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1249 <startgdb+0x89>
lea    0x40(%rsp),%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
jmp    1250 <startgdb+0x90>
movw   $0x2e,0x40(%rsp)
lea    0xdb4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10e0 <fork@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     1359 <startgdb+0x199>
mov    %r14,0x2e0f(%rip)
test   %r14,%r14
jne    1375 <startgdb+0x1b5>
xor    %edi,%edi
xor    %esi,%esi
call   10a0 <setpgid@plt>
lea    0xda4(%rip),%rsi
lea    0xd7f(%rip),%rcx
lea    0x440(%rsp),%rdi
lea    0x40(%rsp),%rdx
mov    %rsp,%r8
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xd9a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1405 <startgdb+0x245>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
lea    0xdbd(%rip),%r12
lea    0xdb3(%rip),%r13
lea    0xda9(%rip),%rbp
lea    0xd9c(%rip),%r14
lea    0xd91(%rip),%r10
lea    0xd85(%rip),%r15
lea    0xd7a(%rip),%r11
lea    0xd51(%rip),%rdi
lea    0xd50(%rip),%rsi
lea    0xd50(%rip),%rdx
lea    0xd10(%rip),%rcx
lea    0xd49(%rip),%r8
mov    %rbx,%r9
xor    %eax,%eax
push   $0x0
lea    0x448(%rsp),%rbx
push   %rbx
push   %r12
push   %r13
push   %rbp
push   %r14
push   %r10
push   %r15
push   %r11
lea    0xd2f(%rip),%rbp
push   %rbp
call   10c0 <execlp@plt>
add    $0x50,%rsp
jmp    1375 <startgdb+0x1b5>
test   %r14,%r14
jne    1391 <startgdb+0x1d1>
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %rax,0x2d1c(%rip)
xor    %edi,%edi
xor    %esi,%esi
call   10a0 <setpgid@plt>
mov    $0xa,%edi
call   10d0 <sleep@plt>
add    $0x1448,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc68(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
sub    $0x8,%rsp
lea    0xc75(%rip),%rdi
lea    0xc4f(%rip),%rdx
lea    0xc4d(%rip),%r8
lea    0x48(%rsp),%rcx
mov    %rdi,%rsi
mov    %rbx,%r9
xor    %eax,%eax
push   $0x0
call   10c0 <execlp@plt>
add    $0x10,%rsp
lea    0xc38(%rip),%rdi
call   1090 <perror@plt>
mov    0x2be2(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <kill@plt>
jmp    137f <startgdb+0x1bf>
lea    0xc8d(%rip),%rbp
lea    0xc83(%rip),%r12
lea    0xc79(%rip),%r10
lea    0xc6c(%rip),%r11
lea    0xc61(%rip),%r14
lea    0xc55(%rip),%r15
lea    0xc28(%rip),%rdi
lea    0xc27(%rip),%rsi
lea    0xc27(%rip),%rdx
lea    0xbe7(%rip),%rcx
lea    0xc2a(%rip),%r8
lea    0xc27(%rip),%r9
xor    %eax,%eax
push   $0x0
lea    0x448(%rsp),%rbx
push   %rbx
push   %rbp
push   %r12
push   %r10
push   %r11
push   %r14
push   %r15
call   10c0 <execlp@plt>
add    $0x40,%rsp
lea    0xc1b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@startgdb.dpid = internal global i64 0
@WNOHANG = global i32 0
@.str = [4 x i8] c"%ld\00"
@.str.1 = [7 x i8] c"GDEBUG\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [8 x i8] c"DISPLAY\00"
@.str.5 = [4 x i8] c"gdb\00"
@.str.6 = [5 x i8] c"-dir\00"
@.str.7 = [10 x i8] c"/dev/null\00"
@.str.8 = [20 x i8] c"Error attaching gdb\00"
@SIGKILL = global i32 0
@.str.9 = [27 x i8] c"exec gdb -dir '%s' '%s' %s\00"
@.str.10 = [13 x i8] c"GDB_GEOMETRY\00"
@.str.11 = [6 x i8] c"xterm\00"
@.str.12 = [7 x i8] c"xterm \00"
@.str.13 = [7 x i8] c"-title\00"
@.str.14 = [10 x i8] c"-geometry\00"
@.str.15 = [4 x i8] c"-sb\00"
@.str.16 = [4 x i8] c"-sl\00"
@.str.17 = [5 x i8] c"2012\00"
@.str.18 = [4 x i8] c"-fn\00"
@.str.19 = [6 x i8] c"10x20\00"
@.str.20 = [3 x i8] c"-e\00"
@.str.21 = [3 x i8] c"sh\00"
@.str.22 = [3 x i8] c"-c\00"
@.str.23 = [26 x i8] c"Error attaching xterm/gdb\00"
define void @startgdb() {
%1 = alloca i8*
%2 = alloca [1024 x i8]
%3 = alloca [20 x i8]
%4 = alloca [4096 x i8]
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca [20 x i8]
%9 = load i64, i64* @startgdb.dpid
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %0
%12 = load i64, i64* @startgdb.dpid
%13 = load i32, i32* @WNOHANG
%14 = call i64 @waitpid(i64 %12, i32* %5, i32 %13)
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = load i64, i64* @startgdb.dpid
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load i64, i64* @startgdb.dpid
%20 = call i32 @kill(i64 %19, i32 0)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18
br label %88
23: ; preds = %18, %11
br label %24
24: ; preds = %23, %0
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%26 = call i64 (...) @getpid()
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %26)
%28 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %28, i8** %1
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%32 = load i8*, i8** %1
%33 = call i32 (i8*, i8*, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %37
34: ; preds = %24
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %34, %30
%38 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i8* %38, i8** %1
%39 = icmp ne i8* %38, null
br i1 %39, label %60, label %40
40: ; preds = %37
%41 = call i64 (...) @fork()
store i64 %41, i64* %7
%42 = load i64, i64* %7
%43 = icmp ne i64 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %40
%45 = call i64 (...) @getpid()
store i64 %45, i64* @startgdb.dpid
%46 = call i32 @setpgid(i32 0, i32 0)
br label %59
47: ; preds = %40
%48 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%49 = load i64, i64* %7
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %49)
%51 = call i32 @sleep(i32 1)
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%54 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %52, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %53, i8* null)
%55 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%56 = load i64, i64* %7
%57 = load i32, i32* @SIGKILL
%58 = call i32 @kill(i64 %56, i32 %57)
br label %88
59: ; preds = %44
br label %86
60: ; preds = %37
%61 = call i64 (...) @fork()
store i64 %61, i64* @startgdb.dpid
%62 = load i64, i64* @startgdb.dpid
%63 = icmp ne i64 %62, 0
br i1 %63, label %85, label %64
64: ; preds = %60
%65 = call i32 @setpgid(i32 0, i32 0)
%66 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%68 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%69 = call i32 (i8*, i8*, ...) @sprintf(i8* %66, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %67, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %68)
%70 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
store i8* %70, i8** %1
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %79
72: ; preds = %64
%73 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%74 = load i8*, i8** %1
%75 = call i32 (i8*, i8*, ...) @sprintf(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %74)
%76 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%77 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%78 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i8* %76, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.19, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.21, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.22, i64 0, i64 0), i8* %77, i8* null)
br label %84
79: ; preds = %64
%80 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%81 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.19, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.21, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.22, i64 0, i64 0), i8* %80, i8* null)
%82 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.23, i64 0, i64 0))
%83 = call i32 @_exit(i32 1)
unreachable
84: ; preds = %72
br label %85
85: ; preds = %84, %60
br label %86
86: ; preds = %85, %59
%87 = call i32 @sleep(i32 10)
br label %88
88: ; preds = %86, %47, %22
ret void
}

LLVM IR (-O2):
@startgdb.dpid = internal unnamed_addr global i64 0
@WNOHANG = global i32 0
@.str = [4 x i8] c"%ld\00"
@.str.1 = [7 x i8] c"GDEBUG\00"
@.str.4 = [8 x i8] c"DISPLAY\00"
@.str.5 = [4 x i8] c"gdb\00"
@.str.6 = [5 x i8] c"-dir\00"
@.str.7 = [10 x i8] c"/dev/null\00"
@.str.8 = [20 x i8] c"Error attaching gdb\00"
@SIGKILL = global i32 0
@.str.9 = [27 x i8] c"exec gdb -dir '%s' '%s' %s\00"
@.str.10 = [13 x i8] c"GDB_GEOMETRY\00"
@.str.11 = [6 x i8] c"xterm\00"
@.str.12 = [7 x i8] c"xterm \00"
@.str.13 = [7 x i8] c"-title\00"
@.str.14 = [10 x i8] c"-geometry\00"
@.str.15 = [4 x i8] c"-sb\00"
@.str.16 = [4 x i8] c"-sl\00"
@.str.17 = [5 x i8] c"2012\00"
@.str.18 = [4 x i8] c"-fn\00"
@.str.19 = [6 x i8] c"10x20\00"
@.str.20 = [3 x i8] c"-e\00"
@.str.21 = [3 x i8] c"sh\00"
@.str.22 = [3 x i8] c"-c\00"
@.str.23 = [26 x i8] c"Error attaching xterm/gdb\00"
define void @startgdb() {
%1 = alloca [1024 x i8]
%2 = alloca [20 x i8]
%3 = alloca [4096 x i8]
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%9 = load i64, i64* @startgdb.dpid
%10 = icmp eq i64 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %0
%12 = bitcast i32* %4 to i8*
%13 = load i32, i32* @WNOHANG
%14 = call i64 @waitpid(i64 %9, i32* %4, i32 %13)
%15 = load i64, i64* @startgdb.dpid
%16 = icmp eq i64 %14, %15
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = call i32 @kill(i64 %15, i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
br label %64
21: ; preds = %11, %17
br label %22
22: ; preds = %21, %0
%23 = call i64 (...) @getpid()
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = call i8* @strcpy(i8* %6, i8* %25)
br label %31
29: ; preds = %22
%30 = bitcast [1024 x i8]* %1 to i16*
store i16 46, i16* %30
br label %31
31: ; preds = %29, %27
%32 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i8* %32, null
%34 = call i64 (...) @fork()
br i1 %33, label %35, label %47
35: ; preds = %31
%36 = icmp eq i64 %34, 0
br i1 %36, label %37, label %40
37: ; preds = %35
%38 = call i64 (...) @getpid()
store i64 %38, i64* @startgdb.dpid
%39 = call i32 @setpgid(i32 0, i32 0)
br label %62
40: ; preds = %35
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %34)
%42 = call i32 @sleep(i32 1)
%43 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %7, i8* null)
%44 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%45 = load i32, i32* @SIGKILL
%46 = call i32 @kill(i64 %34, i32 %45)
br label %64
47: ; preds = %31
store i64 %34, i64* @startgdb.dpid
%48 = icmp eq i64 %34, 0
br i1 %48, label %49, label %62
49: ; preds = %47
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%51 = call i32 @setpgid(i32 0, i32 0)
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %7)
%53 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%54 = icmp eq i8* %53, null
br i1 %54, label %58, label %55
55: ; preds = %49
%56 = call i8* @strcpy(i8* %50, i8* %53)
%57 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i8* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.19, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.21, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.22, i64 0, i64 0), i8* %8, i8* null)
br label %62
58: ; preds = %49
%59 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.19, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.21, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.22, i64 0, i64 0), i8* %8, i8* null)
%60 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.23, i64 0, i64 0))
%61 = call i32 @_exit(i32 1)
unreachable
62: ; preds = %37, %47, %55
%63 = call i32 @sleep(i32 10)
br label %64
64: ; preds = %40, %20, %62
ret void
}