#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 */
struct sock_filter {
  int dummy;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_ATTACH;
int /*<<< orphan*/ PTRACE_SECCOMP_GET_FILTER;
int /*<<< orphan*/ dump_filter(char *, unsigned int, struct sock_filter *,
                               long);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(struct sock_filter *);
struct sock_filter *malloc(long);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ ptrace(int /*<<< orphan*/, scalar_t__, unsigned int,
                  struct sock_filter *);
scalar_t__ remove(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, ...);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc != 2)
    goto usage;
  pid_t pid = (pid_t)strtol(argv[1], NULL, 10);
  if (pid <= 0)
    goto usage;
  printf("** Attaching to process with pid %d **\n", pid);
  long rv = ptrace(PTRACE_ATTACH, pid, 0, 0);
  if (rv != 0) {
    printf("Error: Cannot attach: %s\n", strerror(errno));
    exit(1);
  }
  waitpid(pid, NULL, 0);
  printf("Attached\n");
  char dname[1024];
  snprintf(dname, 1024, "/tmp/seccomp-%d", pid);
  printf("** Creating directory %s **\n", dname);
  if (mkdir(dname, 0755) < 0) {
    printf("Error: Cannot create directory: %s\n", strerror(errno));
    exit(1);
  }
  printf("Created\n");
  printf("** Extracting seccomp filters **\n");
  unsigned cnt = 0;
  while ((rv = ptrace(PTRACE_SECCOMP_GET_FILTER, pid, cnt, NULL)) > 0) {
    struct sock_filter *f = malloc(rv * sizeof(struct sock_filter));
    if (!f) {
      char msgout[256];
      snprintf(msgout, 256, "Error %d: %s", 89, ("malloc"));
      perror(msgout);
      exit(1);
    };
    if (ptrace(PTRACE_SECCOMP_GET_FILTER, pid, cnt, f) < 0) {
      char msgout[256];
      snprintf(msgout, 256, "Error %d: %s", 91, ("ptrace"));
      perror(msgout);
      exit(1);
    };
    dump_filter(dname, cnt, f, rv);
    free(f);
    cnt++;
  }
  if (cnt)
    printf("Dumped %u filters\n", cnt);
  else {
    printf("No seccomp filter was found\n");
    printf("** Cleanup **\n");
    if (remove(dname) == 0)
      printf("Removed %s\n", dname);
    else
      printf("Could not remove %s: %s\n", dname, strerror(errno));
  }
  printf("Bye ...\n");
  return 0;
usage:
  printf("Usage: %s <PID>\n", argv[0]);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f8 <main+0x28>
jmp    1531 <main+0x361>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1090 <strtol@plt>
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jg     1224 <main+0x54>
jmp    1531 <main+0x361>
mov    -0x18(%rbp),%rsi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   10b0 <ptrace@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1286 <main+0xb6>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10c0 <waitpid@plt>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    $0x400,%esi
lea    0xd90(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x420(%rbp),%rsi
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
cmp    $0x0,%rax
jge    131c <main+0x14c>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x424(%rbp)
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x424(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   10b0 <ptrace@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jle    146c <main+0x29c>
mov    -0x20(%rbp),%rdi
shl    $0x2,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
jne    13ca <main+0x1fa>
lea    -0x530(%rbp),%rdi
mov    $0x100,%esi
lea    0xd27(%rip),%rdx
mov    $0x59,%ecx
lea    0xd28(%rip),%r8
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x530(%rbp),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x424(%rbp),%edx
mov    -0x430(%rbp),%rcx
call   10b0 <ptrace@plt>
cmp    $0x0,%rax
jge    142f <main+0x25f>
lea    -0x630(%rbp),%rdi
mov    $0x100,%esi
lea    0xcc2(%rip),%rdx
mov    $0x5b,%ecx
lea    0xcca(%rip),%r8
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x630(%rbp),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%esi
mov    -0x430(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1080 <dump_filter@plt>
mov    -0x430(%rbp),%rdi
call   1030 <free@plt>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    1342 <main+0x172>
cmpl   $0x0,-0x424(%rbp)
je     1492 <main+0x2c2>
mov    -0x424(%rbp),%esi
lea    0xc5d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1517 <main+0x347>
lea    0xc5d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc6c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <remove@plt>
cmp    $0x0,%rax
jne    14de <main+0x30e>
lea    -0x420(%rbp),%rsi
lea    0xc50(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1512 <main+0x342>
lea    -0x420(%rbp),%rax
mov    %rax,-0x638(%rbp)
mov    0x2add(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x638(%rbp),%rsi
mov    %rax,%rdx
lea    0xc23(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1517 <main+0x347>
lea    0xc29(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    154d <main+0x37d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xc11(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x508,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1373 <main+0x193>
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <strtol@plt>
test   %eax,%eax
jle    1373 <main+0x193>
mov    %eax,%ebp
movslq %eax,%r14
lea    0xddf(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   10c0 <ptrace@plt>
test   %rax,%rax
jne    146b <main+0x28b>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
lea    0xe9b(%rip),%rdi
call   1060 <puts@plt>
lea    0xdda(%rip),%rdx
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1080 <snprintf@plt>
lea    0xdca(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
test   %rax,%rax
js     1482 <main+0x2a2>
lea    0xe51(%rip),%rdi
call   1060 <puts@plt>
lea    0xe4d(%rip),%rdi
call   1060 <puts@plt>
mov    0x2d29(%rip),%rbp
mov    0x0(%rbp),%edi
xor    %r12d,%r12d
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   10c0 <ptrace@plt>
test   %rax,%rax
jle    138b <main+0x1ab>
mov    %rax,%r13
lea    0x100(%rsp),%r15
nopl   (%rax)
lea    0x0(,%r13,4),%rdi
call   10b0 <malloc@plt>
test   %rax,%rax
je     1414 <main+0x234>
mov    %rax,%rbx
mov    0x0(%rbp),%edi
mov    %r14,%rsi
mov    %r12d,%edx
mov    %rax,%rcx
call   10c0 <ptrace@plt>
test   %rax,%rax
js     1434 <main+0x254>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1090 <dump_filter@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x1,%r12d
mov    0x0(%rbp),%edi
mov    %r14,%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
call   10c0 <ptrace@plt>
mov    %rax,%r13
test   %rax,%rax
jg     12f0 <main+0x110>
test   %r12d,%r12d
je     138b <main+0x1ab>
lea    0xd4a(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    13f4 <main+0x214>
mov    (%rbx),%rsi
lea    0xd69(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    1402 <main+0x222>
lea    0xd97(%rip),%rdi
call   1060 <puts@plt>
lea    0xda7(%rip),%rdi
call   1060 <puts@plt>
lea    0x100(%rsp),%rdi
call   1040 <remove@plt>
test   %rax,%rax
je     13de <main+0x1fe>
mov    0x2c14(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd03(%rip),%rdi
lea    0x100(%rsp),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    13f4 <main+0x214>
lea    0xcdc(%rip),%rdi
lea    0x100(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd58(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
add    $0x508,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc78(%rip),%rdx
lea    0xc7e(%rip),%r8
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    $0x59,%ecx
jmp    1452 <main+0x272>
lea    0xc58(%rip),%rdx
lea    0xc65(%rip),%r8
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    $0x5b,%ecx
xor    %eax,%eax
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2b5e(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xba8(%rip),%rdi
jmp    1497 <main+0x2b7>
mov    0x2b47(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xbd8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sock_filter = type { i32 }
@.str = [40 x i8] c"** Attaching to process with pid %d **\0A\00"
@PTRACE_ATTACH = global i32 0
@.str.1 = [26 x i8] c"Error: Cannot attach: %s\0A\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"Attached\0A\00"
@.str.3 = [16 x i8] c"/tmp/seccomp-%d\00"
@.str.4 = [29 x i8] c"** Creating directory %s **\0A\00"
@.str.5 = [36 x i8] c"Error: Cannot create directory: %s\0A\00"
@.str.6 = [9 x i8] c"Created\0A\00"
@.str.7 = [34 x i8] c"** Extracting seccomp filters **\0A\00"
@PTRACE_SECCOMP_GET_FILTER = global i32 0
@.str.8 = [13 x i8] c"Error %d: %s\00"
@.str.9 = [7 x i8] c"malloc\00"
@.str.10 = [7 x i8] c"ptrace\00"
@.str.11 = [19 x i8] c"Dumped %u filters\0A\00"
@.str.12 = [29 x i8] c"No seccomp filter was found\0A\00"
@.str.13 = [15 x i8] c"** Cleanup **\0A\00"
@.str.14 = [12 x i8] c"Removed %s\0A\00"
@.str.15 = [25 x i8] c"Could not remove %s: %s\0A\00"
@.str.16 = [9 x i8] c"Bye ...\0A\00"
@.str.17 = [17 x i8] c"Usage: %s <PID>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca %struct.sock_filter*
%11 = alloca [256 x i8]
%12 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %16
15: ; preds = %2
br label %123
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strtol(i8* %19, i32* null, i32 10)
%21 = sext i32 %20 to i64
store i64 %21, i64* %6
%22 = load i64, i64* %6
%23 = icmp sle i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %16
br label %123
25: ; preds = %16
%26 = load i64, i64* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i64 %26)
%28 = load i32, i32* @PTRACE_ATTACH
%29 = load i64, i64* %6
%30 = call i64 @ptrace(i32 %28, i64 %29, i32 0, %struct.sock_filter* null)
store i64 %30, i64* %7
%31 = load i64, i64* %7
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %25
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %25
%39 = load i64, i64* %6
%40 = call i32 @waitpid(i64 %39, i32* null, i32 0)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%43 = load i64, i64* %6
%44 = trunc i64 %43 to i32
%45 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %42, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%49 = call i64 @mkdir(i8* %48, i32 493)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %38
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %38
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %9
br label %59
59: ; preds = %90, %56
%60 = load i32, i32* @PTRACE_SECCOMP_GET_FILTER
%61 = load i64, i64* %6
%62 = load i32, i32* %9
%63 = call i64 @ptrace(i32 %60, i64 %61, i32 %62, %struct.sock_filter* null)
store i64 %63, i64* %7
%64 = icmp sgt i64 %63, 0
br i1 %64, label %65, label %100
65: ; preds = %59
%66 = load i64, i64* %7
%67 = mul i64 %66, 4
%68 = call %struct.sock_filter* @malloc(i64 %67)
store %struct.sock_filter* %68, %struct.sock_filter** %10
%69 = load %struct.sock_filter*, %struct.sock_filter** %10
%70 = icmp ne %struct.sock_filter* %69, null
br i1 %70, label %77, label %71
71: ; preds = %65
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%73 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %72, i32 256, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 89, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%75 = call i32 @perror(i8* %74)
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %65
%78 = load i32, i32* @PTRACE_SECCOMP_GET_FILTER
%79 = load i64, i64* %6
%80 = load i32, i32* %9
%81 = load %struct.sock_filter*, %struct.sock_filter** %10
%82 = call i64 @ptrace(i32 %78, i64 %79, i32 %80, %struct.sock_filter* %81)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %90
84: ; preds = %77
%85 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%86 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %85, i32 256, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 91, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%88 = call i32 @perror(i8* %87)
%89 = call i32 @exit(i32 1)
unreachable
90: ; preds = %77
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%92 = load i32, i32* %9
%93 = load %struct.sock_filter*, %struct.sock_filter** %10
%94 = load i64, i64* %7
%95 = call i32 @dump_filter(i8* %91, i32 %92, %struct.sock_filter* %93, i64 %94)
%96 = load %struct.sock_filter*, %struct.sock_filter** %10
%97 = call i32 @free(%struct.sock_filter* %96)
%98 = load i32, i32* %9
%99 = add i32 %98, 1
store i32 %99, i32* %9
br label %59
100: ; preds = %59
%101 = load i32, i32* %9
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %100
%104 = load i32, i32* %9
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 %104)
br label %121
106: ; preds = %100
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0))
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
%109 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%110 = call i64 @remove(i8* %109)
%111 = icmp eq i64 %110, 0
br i1 %111, label %112, label %115
112: ; preds = %106
%113 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i8* %113)
br label %120
115: ; preds = %106
%116 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%117 = load i32, i32* @errno
%118 = call i8* @strerror(i32 %117)
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.15, i64 0, i64 0), i8* %116, i8* %118)
br label %120
120: ; preds = %115, %112
br label %121
121: ; preds = %120, %103
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* %3
br label %128
123: ; preds = %24, %15
%124 = load i8**, i8*** %5
%125 = getelementptr inbounds i8*, i8** %124, i64 0
%126 = load i8*, i8** %125
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.17, i64 0, i64 0), i8* %126)
store i32 1, i32* %3
br label %128
128: ; preds = %123, %121
%129 = load i32, i32* %3
ret i32 %129
}

LLVM IR (-O2):
%struct.sock_filter = type { i32 }
@.str = [40 x i8] c"** Attaching to process with pid %d **\0A\00"
@PTRACE_ATTACH = global i32 0
@.str.1 = [26 x i8] c"Error: Cannot attach: %s\0A\00"
@errno = global i32 0
@.str.3 = [16 x i8] c"/tmp/seccomp-%d\00"
@.str.4 = [29 x i8] c"** Creating directory %s **\0A\00"
@.str.5 = [36 x i8] c"Error: Cannot create directory: %s\0A\00"
@PTRACE_SECCOMP_GET_FILTER = global i32 0
@.str.8 = [13 x i8] c"Error %d: %s\00"
@.str.9 = [7 x i8] c"malloc\00"
@.str.10 = [7 x i8] c"ptrace\00"
@.str.11 = [19 x i8] c"Dumped %u filters\0A\00"
@.str.14 = [12 x i8] c"Removed %s\0A\00"
@.str.15 = [25 x i8] c"Could not remove %s: %s\0A\00"
@.str.17 = [17 x i8] c"Usage: %s <PID>\0A\00"
@str = [9 x i8] c"Attached\00"
@str.18 = [8 x i8] c"Created\00"
@str.19 = [33 x i8] c"** Extracting seccomp filters **\00"
@str.20 = [28 x i8] c"No seccomp filter was found\00"
@str.21 = [14 x i8] c"** Cleanup **\00"
@str.22 = [8 x i8] c"Bye ...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %86
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strtol(i8* nocapture %9, i32* null, i32 10)
%11 = sext i32 %10 to i64
%12 = icmp slt i32 %10, 1
br i1 %12, label %86, label %13
13: ; preds = %7
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i64 %11)
%15 = load i32, i32* @PTRACE_ATTACH
%16 = tail call i64 @ptrace(i32 %15, i64 %11, i32 0, %struct.sock_filter* null)
%17 = icmp eq i64 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %13
%24 = tail call i32 @waitpid(i64 %11, i32* null, i32 0)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%27 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %26, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%29 = call i64 @mkdir(i8* %26, i32 493)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %23
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %23
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.18, i64 0, i64 0))
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.19, i64 0, i64 0))
%39 = load i32, i32* @PTRACE_SECCOMP_GET_FILTER
%40 = call i64 @ptrace(i32 %39, i64 %11, i32 0, %struct.sock_filter* null)
%41 = icmp sgt i64 %40, 0
br i1 %41, label %42, label %73
42: ; preds = %36, %62
%43 = phi i64 [ %67, %62 ], [ %40, %36 ]
%44 = phi i32 [ %65, %62 ], [ 0, %36 ]
%45 = shl i64 %43, 2
%46 = call %struct.sock_filter* @malloc(i64 %45)
%47 = icmp eq %struct.sock_filter* %46, null
br i1 %47, label %48, label %53
48: ; preds = %42
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%50 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %49, i32 256, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 89, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%51 = call i32 @perror(i8* %49)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %42
%54 = load i32, i32* @PTRACE_SECCOMP_GET_FILTER
%55 = call i64 @ptrace(i32 %54, i64 %11, i32 %44, %struct.sock_filter* %46)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %53
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%59 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %58, i32 256, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 91, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%60 = call i32 @perror(i8* %58)
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %53
%63 = call i32 @dump_filter(i8* %26, i32 %44, %struct.sock_filter* %46, i64 %43)
%64 = call i32 @free(%struct.sock_filter* %46)
%65 = add i32 %44, 1
%66 = load i32, i32* @PTRACE_SECCOMP_GET_FILTER
%67 = call i64 @ptrace(i32 %66, i64 %11, i32 %65, %struct.sock_filter* null)
%68 = icmp sgt i64 %67, 0
br i1 %68, label %42, label %69
69: ; preds = %62
%70 = icmp eq i32 %65, 0
br i1 %70, label %73, label %71
71: ; preds = %69
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 %65)
br label %84
73: ; preds = %36, %69
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.20, i64 0, i64 0))
%75 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.21, i64 0, i64 0))
%76 = call i64 @remove(i8* %26)
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %73
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i8* %26)
br label %84
80: ; preds = %73
%81 = load i32, i32* @errno
%82 = call i8* @strerror(i32 %81)
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.15, i64 0, i64 0), i8* %26, i8* %82)
br label %84
84: ; preds = %78, %80, %71
%85 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.22, i64 0, i64 0))
br label %89
86: ; preds = %7, %2
%87 = load i8*, i8** %1
%88 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.17, i64 0, i64 0), i8* %87)
br label %89
89: ; preds = %86, %84
%90 = phi i32 [ 1, %86 ], [ 0, %84 ]
ret i32 %90
}