#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 /*<<< orphan*/ exclusions;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strcmp(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ *strstr(char *, char *);
int main(int argc, char **argv) {
  const char *exclusions[] = {"mem", "fd", "kcore"};
  if (argc != 2) {
    printf("Usage: %s [/proc]/XX/fileToDump\n", argv[0]);
    printf("Note: Only files under /proc can be dumped\n");
    printf("Sample: to dump /proc/net/ip_conntrack, use %s net/ip_conntrack - "
           "do not provide /proc at the beginning\n",
           argv[0]);
    exit(-5);
  } else {
    char *fname = malloc(7 + strlen(argv[1]));
    strcat(fname, "/proc/");
    strcat(fname, argv[1]);
    if (NULL != strstr(fname, "..")) {
      printf(".. is forbidden (%s)\n", argv[1]);
      exit(-5);
    }
    for (int i = 0; i < sizeof(exclusions) / sizeof(exclusions[0]); i++) {
      int diff = strlen(fname) - strlen(exclusions[i]);
      if ((diff >= 0) && (0 == strcmp(&fname[diff], exclusions[i]))) {
        printf("Dump of /proc/%s is forbidden\n", argv[1]);
        exit(-4);
      }
      char *exclusionPattern = malloc(3 + strlen(exclusions[i]));
      strcat(exclusionPattern, "/");
      strcat(exclusionPattern, exclusions[i]);
      strcat(exclusionPattern, "/");
      if (NULL != strstr(fname, exclusionPattern)) {
        printf("Dump of /proc/%s is forbidden\n", argv[1]);
        exit(-3);
      }
    }
    setuid(0);
    FILE *fp;
    fp = fopen(fname, "r");
    char buf[8192];
    if (NULL != fp) {
      int nread = 0;
      while ((nread = fread(buf, 1, sizeof buf, fp)) > 0) {
        fwrite(buf, 1, nread, stdout);
      }
      if (ferror(fp)) {
        exit(-1);
      }
      fclose(fp);
      exit(0);
    } else {
      exit(-2);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2060,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c10(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c0d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c0a(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1256 <main+0x86>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xfffffffb,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x7,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10b0 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12d0 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xfffffffb,%edi
call   10c0 <exit@plt>
movl   $0x0,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    $0x3,%rax
jae    13fc <main+0x22c>
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x2058(%rbp)
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x2058(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jl     1360 <main+0x190>
mov    -0x38(%rbp),%rdi
movslq -0x40(%rbp),%rax
add    %rax,%rdi
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
call   1080 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1360 <main+0x190>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xfffffffc,%edi
call   10c0 <exit@plt>
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x3,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xd41(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x48(%rbp),%rdi
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
call   10b0 <strcat@plt>
mov    -0x48(%rbp),%rdi
lea    0xd1f(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10f0 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     13e9 <main+0x219>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xfffffffd,%edi
call   10c0 <exit@plt>
jmp    13ee <main+0x21e>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12d7 <main+0x107>
xor    %edi,%edi
call   10e0 <setuid@plt>
mov    -0x38(%rbp),%rdi
lea    0xcf4(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x50(%rbp)
xor    %eax,%eax
cmp    -0x50(%rbp),%rax
je     14a8 <main+0x2d8>
movl   $0x0,-0x2054(%rbp)
lea    -0x2050(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2000,%edx
call   1040 <fread@plt>
mov    %eax,-0x2054(%rbp)
cmp    $0x0,%eax
jle    147b <main+0x2ab>
lea    -0x2050(%rbp),%rdi
mov    -0x2054(%rbp),%edx
mov    0x2b76(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10d0 <fwrite@plt>
jmp    142d <main+0x25d>
mov    -0x50(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1498 <main+0x2c8>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    $0xfffffffe,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2000,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    13a5 <main+0x1c5>
mov    0x8(%rbx),%rdi
call   1070 <strlen@plt>
lea    0x7(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
lea    0xe81(%rip),%rsi
mov    %rax,%rdi
call   10c0 <strcat@plt>
mov    0x8(%rbx),%rsi
mov    %r14,%rdi
call   10c0 <strcat@plt>
lea    0xe6d(%rip),%rsi
mov    %r14,%rdi
call   1100 <strstr@plt>
test   %rax,%rax
jne    13ce <main+0x1ee>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
lea    0xdad(%rip),%rdi
call   1070 <strlen@plt>
sub    %eax,%ebp
js     1276 <main+0x96>
mov    %ebp,%edi
add    %r14,%rdi
lea    0xd98(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1389 <main+0x1a9>
lea    0xd83(%rip),%r15
mov    %r15,%rdi
call   1070 <strlen@plt>
lea    0x3(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
lea    0xe05(%rip),%r12
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10c0 <strcat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   10c0 <strcat@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1100 <strstr@plt>
test   %rax,%rax
jne    1461 <main+0x281>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
lea    0xd27(%rip),%rdi
call   1070 <strlen@plt>
sub    %eax,%ebp
js     1300 <main+0x120>
mov    %ebp,%edi
add    %r14,%rdi
lea    0xd12(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1389 <main+0x1a9>
lea    0xcfd(%rip),%r15
mov    %r15,%rdi
call   1070 <strlen@plt>
lea    0x3(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
lea    0xd7b(%rip),%r12
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10c0 <strcat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   10c0 <strcat@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1100 <strstr@plt>
test   %rax,%rax
jne    1461 <main+0x281>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
lea    0xca0(%rip),%rdi
call   1070 <strlen@plt>
sub    %eax,%ebp
js     13ea <main+0x20a>
mov    %ebp,%eax
mov    %r14,%rdi
add    %rax,%rdi
lea    0xc88(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    13ea <main+0x20a>
mov    0x8(%rbx),%rsi
lea    0xd23(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xfffffffc,%edi
call   10d0 <exit@plt>
mov    (%rbx),%rsi
lea    0xc5e(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd1b(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xc62(%rip),%rdi
jmp    13d9 <main+0x1f9>
mov    0x8(%rbx),%rsi
lea    0xcc8(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xfffffffb,%edi
call   10d0 <exit@plt>
lea    0xc16(%rip),%r15
mov    %r15,%rdi
call   1070 <strlen@plt>
lea    0x3(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
lea    0xc91(%rip),%r12
mov    %rax,%rdi
mov    %r12,%rsi
call   10c0 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10c0 <strcat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   10c0 <strcat@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1100 <strstr@plt>
test   %rax,%rax
jne    1461 <main+0x281>
xor    %edi,%edi
call   10f0 <setuid@plt>
lea    0xc8c(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    147d <main+0x29d>
mov    $0xfffffffe,%edi
call   10d0 <exit@plt>
mov    0x8(%rbx),%rsi
lea    0xc4b(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xfffffffd,%edi
call   10d0 <exit@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jle    14db <main+0x2fb>
mov    0x2b40(%rip),%rbp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   10e0 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jg     14b0 <main+0x2d0>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    14f7 <main+0x317>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"mem\00"
@.str.1 = [3 x i8] c"fd\00"
@.str.2 = [6 x i8] c"kcore\00"
@__const.main.exclusions = [3 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [33 x i8] c"Usage: %s [/proc]/XX/fileToDump\0A\00"
@.str.4 = [44 x i8] c"Note: Only files under /proc can be dumped\0A\00"
@.str.5 = [105 x i8] c"Sample: to dump /proc/net/ip_conntrack, use %s net/ip_conntrack - do not provide /proc at the beginning\0A\00"
@.str.6 = [7 x i8] c"/proc/\00"
@.str.7 = [3 x i8] c"..\00"
@.str.8 = [22 x i8] c".. is forbidden (%s)\0A\00"
@.str.9 = [31 x i8] c"Dump of /proc/%s is forbidden\0A\00"
@.str.10 = [2 x i8] c"/\00"
@.str.11 = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i8*]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca [8192 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [3 x i8*]* %6 to i8*
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %28
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str.5, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 -5)
unreachable
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @strlen(i8* %31)
%33 = add nsw i32 7, %32
%34 = call i8* @malloc(i32 %33)
store i8* %34, i8** %7
%35 = load i8*, i8** %7
%36 = call i32 @strcat(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%37 = load i8*, i8** %7
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strcat(i8* %37, i8* %40)
%42 = load i8*, i8** %7
%43 = call i32* @strstr(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%44 = icmp ne i32* null, %43
br i1 %44, label %45, label %51
45: ; preds = %28
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 -5)
unreachable
51: ; preds = %28
store i32 0, i32* %8
br label %52
52: ; preds = %113, %51
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = icmp ult i64 %54, 3
br i1 %55, label %56, label %116
56: ; preds = %52
%57 = load i8*, i8** %7
%58 = call i32 @strlen(i8* %57)
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 @strlen(i8* %62)
%64 = sub nsw i32 %58, %63
store i32 %64, i32* %9
%65 = load i32, i32* %9
%66 = icmp sge i32 %65, 0
br i1 %66, label %67, label %84
67: ; preds = %56
%68 = load i8*, i8** %7
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 %73
%75 = load i8*, i8** %74
%76 = call i64 @strcmp(i8* %71, i8* %75)
%77 = icmp eq i64 0, %76
br i1 %77, label %78, label %84
78: ; preds = %67
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %81)
%83 = call i32 @exit(i32 -4)
unreachable
84: ; preds = %67, %56
%85 = load i32, i32* %8
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 %86
%88 = load i8*, i8** %87
%89 = call i32 @strlen(i8* %88)
%90 = add nsw i32 3, %89
%91 = call i8* @malloc(i32 %90)
store i8* %91, i8** %10
%92 = load i8*, i8** %10
%93 = call i32 @strcat(i8* %92, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%94 = load i8*, i8** %10
%95 = load i32, i32* %8
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 %96
%98 = load i8*, i8** %97
%99 = call i32 @strcat(i8* %94, i8* %98)
%100 = load i8*, i8** %10
%101 = call i32 @strcat(i8* %100, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%102 = load i8*, i8** %7
%103 = load i8*, i8** %10
%104 = call i32* @strstr(i8* %102, i8* %103)
%105 = icmp ne i32* null, %104
br i1 %105, label %106, label %112
106: ; preds = %84
%107 = load i8**, i8*** %5
%108 = getelementptr inbounds i8*, i8** %107, i64 1
%109 = load i8*, i8** %108
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %109)
%111 = call i32 @exit(i32 -3)
unreachable
112: ; preds = %84
br label %113
113: ; preds = %112
%114 = load i32, i32* %8
%115 = add nsw i32 %114, 1
store i32 %115, i32* %8
br label %52
116: ; preds = %52
%117 = call i32 @setuid(i32 0)
%118 = load i8*, i8** %7
%119 = call i32* @fopen(i8* %118, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
store i32* %119, i32** %11
%120 = load i32*, i32** %11
%121 = icmp ne i32* null, %120
br i1 %121, label %122, label %143
122: ; preds = %116
store i32 0, i32* %13
br label %123
123: ; preds = %128, %122
%124 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 0
%125 = load i32*, i32** %11
%126 = call i32 @fread(i8* %124, i32 1, i32 8192, i32* %125)
store i32 %126, i32* %13
%127 = icmp sgt i32 %126, 0
br i1 %127, label %128, label %133
128: ; preds = %123
%129 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 0
%130 = load i32, i32* %13
%131 = load i32, i32* @stdout
%132 = call i32 @fwrite(i8* %129, i32 1, i32 %130, i32 %131)
br label %123
133: ; preds = %123
%134 = load i32*, i32** %11
%135 = call i64 @ferror(i32* %134)
%136 = icmp ne i64 %135, 0
br i1 %136, label %137, label %139
137: ; preds = %133
%138 = call i32 @exit(i32 -1)
unreachable
139: ; preds = %133
%140 = load i32*, i32** %11
%141 = call i32 @fclose(i32* %140)
%142 = call i32 @exit(i32 0)
unreachable
143: ; preds = %116
%144 = call i32 @exit(i32 -2)
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"mem\00"
@.str.1 = [3 x i8] c"fd\00"
@.str.2 = [6 x i8] c"kcore\00"
@.str.3 = [33 x i8] c"Usage: %s [/proc]/XX/fileToDump\0A\00"
@.str.5 = [105 x i8] c"Sample: to dump /proc/net/ip_conntrack, use %s net/ip_conntrack - do not provide /proc at the beginning\0A\00"
@.str.6 = [7 x i8] c"/proc/\00"
@.str.7 = [3 x i8] c"..\00"
@.str.8 = [22 x i8] c".. is forbidden (%s)\0A\00"
@.str.9 = [31 x i8] c"Dump of /proc/%s is forbidden\0A\00"
@.str.10 = [2 x i8] c"/\00"
@.str.11 = [2 x i8] c"r\00"
@stdout = global i32 0
@str = [43 x i8] c"Note: Only files under /proc can be dumped\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8192 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([105 x i8], [105 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 -5)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 7
%17 = tail call i8* @malloc(i32 %16)
%18 = tail call i32 @strcat(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%19 = load i8*, i8** %13
%20 = tail call i32 @strcat(i8* %17, i8* %19)
%21 = tail call i32* @strstr(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %12
%24 = tail call i32 @strlen(i8* %17)
%25 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%26 = sub nsw i32 %24, %25
%27 = icmp sgt i32 %26, -1
br i1 %27, label %78, label %87
28: ; preds = %12
%29 = load i8*, i8** %13
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %29)
%31 = tail call i32 @exit(i32 -5)
unreachable
32: ; preds = %87
%33 = tail call i32 @strlen(i8* %17)
%34 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = sub nsw i32 %33, %34
%36 = icmp sgt i32 %35, -1
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = zext i32 %35 to i64
%39 = getelementptr inbounds i8, i8* %17, i64 %38
%40 = tail call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %83, label %42
42: ; preds = %37, %32
%43 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%44 = add nsw i32 %43, 3
%45 = tail call i8* @malloc(i32 %44)
%46 = tail call i32 @strcat(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%47 = tail call i32 @strcat(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%48 = tail call i32 @strcat(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%49 = tail call i32* @strstr(i8* dereferenceable(1) %17, i8* dereferenceable(1) %45)
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %96
51: ; preds = %42
%52 = tail call i32 @strlen(i8* %17)
%53 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%54 = sub nsw i32 %52, %53
%55 = icmp sgt i32 %54, -1
br i1 %55, label %56, label %61
56: ; preds = %51
%57 = zext i32 %54 to i64
%58 = getelementptr inbounds i8, i8* %17, i64 %57
%59 = tail call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %83, label %61
61: ; preds = %56, %51
%62 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%63 = add nsw i32 %62, 3
%64 = tail call i8* @malloc(i32 %63)
%65 = tail call i32 @strcat(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%66 = tail call i32 @strcat(i8* %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%67 = tail call i32 @strcat(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%68 = tail call i32* @strstr(i8* dereferenceable(1) %17, i8* dereferenceable(1) %64)
%69 = icmp eq i32* %68, null
br i1 %69, label %70, label %96
70: ; preds = %61
%71 = tail call i32 @setuid(i32 0)
%72 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%73 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%74 = icmp eq i32* %72, null
br i1 %74, label %114, label %75
75: ; preds = %70
%76 = call i32 @fread(i8* %73, i32 1, i32 8192, i32* %72)
%77 = icmp sgt i32 %76, 0
br i1 %77, label %100, label %106
78: ; preds = %23
%79 = zext i32 %26 to i64
%80 = getelementptr inbounds i8, i8* %17, i64 %79
%81 = tail call i64 @strcmp(i8* %80, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %56, %37, %78
%84 = load i8*, i8** %13
%85 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %84)
%86 = tail call i32 @exit(i32 -4)
unreachable
87: ; preds = %78, %23
%88 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%89 = add nsw i32 %88, 3
%90 = tail call i8* @malloc(i32 %89)
%91 = tail call i32 @strcat(i8* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%92 = tail call i32 @strcat(i8* %90, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%93 = tail call i32 @strcat(i8* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%94 = tail call i32* @strstr(i8* dereferenceable(1) %17, i8* dereferenceable(1) %90)
%95 = icmp eq i32* %94, null
br i1 %95, label %32, label %96
96: ; preds = %61, %42, %87
%97 = load i8*, i8** %13
%98 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %97)
%99 = tail call i32 @exit(i32 -3)
unreachable
100: ; preds = %75, %100
%101 = phi i32 [ %104, %100 ], [ %76, %75 ]
%102 = load i32, i32* @stdout
%103 = call i32 @fwrite(i8* %73, i32 1, i32 %101, i32 %102)
%104 = call i32 @fread(i8* %73, i32 1, i32 8192, i32* %72)
%105 = icmp sgt i32 %104, 0
br i1 %105, label %100, label %106
106: ; preds = %100, %75
%107 = call i64 @ferror(i32* %72)
%108 = icmp eq i64 %107, 0
br i1 %108, label %111, label %109
109: ; preds = %106
%110 = call i32 @exit(i32 -1)
unreachable
111: ; preds = %106
%112 = call i32 @fclose(i32* %72)
%113 = call i32 @exit(i32 0)
unreachable
114: ; preds = %70
%115 = tail call i32 @exit(i32 -2)
unreachable
}