#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 size_t ssize_t;
typedef int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int asprintf(char **, char *, int /*<<< orphan*/ const);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
char *pid_proc_comm(int /*<<< orphan*/ const);
size_t read(int, unsigned char *, int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int pid_proc_cmdline_x11_xpra_xephyr(const pid_t pid) {
  char *comm = pid_proc_comm(pid);
  if (comm == NULL)
    return 0;
  if (strcmp(comm, "firejail") != 0) {
    free(comm);
    return 0;
  }
  free(comm);
  char *fname;
  int fd;
  if (asprintf(&fname, "/proc/%d/cmdline", pid) == -1)
    return 0;
  if ((fd = open(fname, O_RDONLY)) < 0) {
    free(fname);
    return 0;
  }
  free(fname);
  unsigned char buffer[4096];
  ssize_t len;
  if ((len = read(fd, buffer, sizeof(buffer) - 1)) <= 0) {
    close(fd);
    return 0;
  }
  buffer[len] = '\0';
  close(fd);
  int i;
  for (i = 0; buffer[i] != '\0'; i++)
    ;
  while (1) {
    i++;
    if (i >= len)
      break;
    char *arg = (char *)buffer + i;
    if (strcmp(arg, "--") == 0)
      break;
    if (strncmp(arg, "--", 2) != 0)
      break;
    if (strcmp(arg, "--x11=xorg") == 0)
      return 0;
    if (strncmp(arg, "--x11", 5) == 0)
      return 1;
    i += strlen(arg);
  }
  return 0;
}


x86 assembly (clang, -O0):
<pid_proc_cmdline_x11_xpra_xephyr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <pid_proc_comm@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c1 <pid_proc_cmdline_x11_xpra_xephyr+0x31>
movl   $0x0,-0x4(%rbp)
jmp    13f8 <pid_proc_cmdline_x11_xpra_xephyr+0x268>
mov    -0x10(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     11f0 <pid_proc_cmdline_x11_xpra_xephyr+0x60>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f8 <pid_proc_cmdline_x11_xpra_xephyr+0x268>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edx
lea    -0x18(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   10a0 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    1221 <pid_proc_cmdline_x11_xpra_xephyr+0x91>
movl   $0x0,-0x4(%rbp)
jmp    13f8 <pid_proc_cmdline_x11_xpra_xephyr+0x268>
mov    -0x18(%rbp),%rdi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1254 <pid_proc_cmdline_x11_xpra_xephyr+0xc4>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f8 <pid_proc_cmdline_x11_xpra_xephyr+0x268>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0xfff,%edx
call   1080 <read@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
ja     1296 <pid_proc_cmdline_x11_xpra_xephyr+0x106>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f8 <pid_proc_cmdline_x11_xpra_xephyr+0x268>
mov    -0x1028(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x102c(%rbp)
movslq -0x102c(%rbp),%rax
movzbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     12e8 <pid_proc_cmdline_x11_xpra_xephyr+0x158>
jmp    12d4 <pid_proc_cmdline_x11_xpra_xephyr+0x144>
mov    -0x102c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x102c(%rbp)
jmp    12b7 <pid_proc_cmdline_x11_xpra_xephyr+0x127>
jmp    12ed <pid_proc_cmdline_x11_xpra_xephyr+0x15d>
mov    -0x102c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x102c(%rbp)
movslq -0x102c(%rbp),%rax
cmp    -0x1028(%rbp),%rax
jb     1315 <pid_proc_cmdline_x11_xpra_xephyr+0x185>
jmp    13f1 <pid_proc_cmdline_x11_xpra_xephyr+0x261>
lea    -0x1020(%rbp),%rax
movslq -0x102c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x1038(%rbp)
mov    -0x1038(%rbp),%rdi
lea    0xcdf(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    134f <pid_proc_cmdline_x11_xpra_xephyr+0x1bf>
jmp    13f1 <pid_proc_cmdline_x11_xpra_xephyr+0x261>
mov    -0x1038(%rbp),%rdi
lea    0xcbd(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1376 <pid_proc_cmdline_x11_xpra_xephyr+0x1e6>
jmp    13f1 <pid_proc_cmdline_x11_xpra_xephyr+0x261>
mov    -0x1038(%rbp),%rdi
lea    0xc99(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    139f <pid_proc_cmdline_x11_xpra_xephyr+0x20f>
movl   $0x0,-0x4(%rbp)
jmp    13f8 <pid_proc_cmdline_x11_xpra_xephyr+0x268>
mov    -0x1038(%rbp),%rdi
lea    0xc7b(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    13cd <pid_proc_cmdline_x11_xpra_xephyr+0x23d>
movl   $0x1,-0x4(%rbp)
jmp    13f8 <pid_proc_cmdline_x11_xpra_xephyr+0x268>
mov    -0x1038(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
movslq -0x102c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x102c(%rbp)
jmp    12ed <pid_proc_cmdline_x11_xpra_xephyr+0x15d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pid_proc_cmdline_x11_xpra_xephyr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %edi,%r14d
call   1050 <pid_proc_comm@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     11d3 <pid_proc_cmdline_x11_xpra_xephyr+0x43>
mov    %rax,%rbx
lea    0xe45(%rip),%rsi
mov    %rax,%rdi
call   1090 <strcmp@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %rbp,%rbp
je     11e8 <pid_proc_cmdline_x11_xpra_xephyr+0x58>
mov    %r13d,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1a(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r14d,%edx
call   10a0 <asprintf@plt>
xor    %r13d,%r13d
cmp    $0xffffffff,%eax
je     11d3 <pid_proc_cmdline_x11_xpra_xephyr+0x43>
mov    0x8(%rsp),%rdi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
test   %ebp,%ebp
js     11d3 <pid_proc_cmdline_x11_xpra_xephyr+0x43>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xfff,%edx
call   1080 <read@plt>
test   %rax,%rax
je     1303 <pid_proc_cmdline_x11_xpra_xephyr+0x173>
mov    %rax,%r14
movb   $0x0,0x10(%rsp,%rax,1)
mov    %ebp,%edi
call   1070 <close@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x0,0x10(%rsp,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1260 <pid_proc_cmdline_x11_xpra_xephyr+0xd0>
mov    %ebx,%eax
xor    %r13d,%r13d
cmp    %rax,%r14
jbe    11d3 <pid_proc_cmdline_x11_xpra_xephyr+0x43>
lea    0xd9a(%rip),%r15
lea    0xd96(%rip),%r12
lea    (%rsp,%rax,1),%rbp
add    $0x10,%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     11d3 <pid_proc_cmdline_x11_xpra_xephyr+0x43>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11d3 <pid_proc_cmdline_x11_xpra_xephyr+0x43>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     11d3 <pid_proc_cmdline_x11_xpra_xephyr+0x43>
mov    %rbp,%rdi
lea    0xd4e(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1312 <pid_proc_cmdline_x11_xpra_xephyr+0x182>
mov    %rbp,%rdi
call   1060 <strlen@plt>
add    %eax,%ebx
add    $0x1,%ebx
movslq %ebx,%rax
cmp    %rax,%r14
ja     1287 <pid_proc_cmdline_x11_xpra_xephyr+0xf7>
jmp    11d3 <pid_proc_cmdline_x11_xpra_xephyr+0x43>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %r13d,%r13d
jmp    11d3 <pid_proc_cmdline_x11_xpra_xephyr+0x43>
mov    $0x1,%r13d
jmp    11d3 <pid_proc_cmdline_x11_xpra_xephyr+0x43>

LLVM IR (-O0):
@.str = [9 x i8] c"firejail\00"
@.str.1 = [17 x i8] c"/proc/%d/cmdline\00"
@O_RDONLY = global i32 0
@.str.2 = [3 x i8] c"--\00"
@.str.3 = [11 x i8] c"--x11=xorg\00"
@.str.4 = [6 x i8] c"--x11\00"
define i32 @pid_proc_cmdline_x11_xpra_xephyr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %3
%11 = load i32, i32* %3
%12 = call i8* @pid_proc_comm(i32 %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 0, i32* %2
br label %105
16: ; preds = %1
%17 = load i8*, i8** %4
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
store i32 0, i32* %2
br label %105
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = call i32 @free(i8* %24)
%26 = load i32, i32* %3
%27 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 0, i32* %2
br label %105
30: ; preds = %23
%31 = load i8*, i8** %5
%32 = load i32, i32* @O_RDONLY
%33 = call i32 @open(i8* %31, i32 %32)
store i32 %33, i32* %6
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i8*, i8** %5
%37 = call i32 @free(i8* %36)
store i32 0, i32* %2
br label %105
38: ; preds = %30
%39 = load i8*, i8** %5
%40 = call i32 @free(i8* %39)
%41 = load i32, i32* %6
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%43 = call i64 @read(i32 %41, i8* %42, i32 4095)
store i64 %43, i64* %8
%44 = icmp ule i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = load i32, i32* %6
%47 = call i32 @close(i32 %46)
store i32 0, i32* %2
br label %105
48: ; preds = %38
%49 = load i64, i64* %8
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %49
store i8 0, i8* %50
%51 = load i32, i32* %6
%52 = call i32 @close(i32 %51)
store i32 0, i32* %9
br label %53
53: ; preds = %61, %48
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %53
br label %61
61: ; preds = %60
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %53
64: ; preds = %53
br label %65
65: ; preds = %64, %97
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
%68 = load i32, i32* %9
%69 = sext i32 %68 to i64
%70 = load i64, i64* %8
%71 = icmp uge i64 %69, %70
br i1 %71, label %72, label %73
72: ; preds = %65
br label %104
73: ; preds = %65
%74 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%75 = load i32, i32* %9
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
store i8* %77, i8** %10
%78 = load i8*, i8** %10
%79 = call i64 @strcmp(i8* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %73
br label %104
82: ; preds = %73
%83 = load i8*, i8** %10
%84 = call i64 @strncmp(i8* %83, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %87
86: ; preds = %82
br label %104
87: ; preds = %82
%88 = load i8*, i8** %10
%89 = call i64 @strcmp(i8* %88, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%90 = icmp eq i64 %89, 0
br i1 %90, label %91, label %92
91: ; preds = %87
store i32 0, i32* %2
br label %105
92: ; preds = %87
%93 = load i8*, i8** %10
%94 = call i64 @strncmp(i8* %93, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %97
96: ; preds = %92
store i32 1, i32* %2
br label %105
97: ; preds = %92
%98 = load i8*, i8** %10
%99 = call i64 @strlen(i8* %98)
%100 = load i32, i32* %9
%101 = sext i32 %100 to i64
%102 = add nsw i64 %101, %99
%103 = trunc i64 %102 to i32
store i32 %103, i32* %9
br label %65
104: ; preds = %86, %81, %72
store i32 0, i32* %2
br label %105
105: ; preds = %104, %96, %91, %45, %35, %29, %20, %15
%106 = load i32, i32* %2
ret i32 %106
}

LLVM IR (-O2):
@.str = [9 x i8] c"firejail\00"
@.str.1 = [17 x i8] c"/proc/%d/cmdline\00"
@O_RDONLY = global i32 0
@.str.2 = [3 x i8] c"--\00"
@.str.3 = [11 x i8] c"--x11=xorg\00"
@.str.4 = [6 x i8] c"--x11\00"
define i32 @pid_proc_cmdline_x11_xpra_xephyr(i32 %0) {
%2 = alloca i8*
%3 = alloca [4096 x i8]
%4 = tail call i8* @pid_proc_comm(i32 %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %67, label %6
6: ; preds = %1
%7 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = tail call i32 @free(i8* %4)
br i1 %8, label %10, label %67
10: ; preds = %6
%11 = bitcast i8** %2 to i8*
%12 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %65, label %14
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
%18 = icmp slt i32 %17, 0
%19 = load i8*, i8** %2
%20 = call i32 @free(i8* %19)
br i1 %18, label %65, label %21
21: ; preds = %14
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%23 = call i64 @read(i32 %17, i8* %22, i32 4095)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @close(i32 %17)
br label %63
27: ; preds = %21
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %23
store i8 0, i8* %28
%29 = call i32 @close(i32 %17)
br label %30
30: ; preds = %30, %27
%31 = phi i64 [ %35, %30 ], [ 0, %27 ]
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
%35 = add nuw i64 %31, 1
br i1 %34, label %36, label %30
36: ; preds = %30
%37 = trunc i64 %31 to i32
%38 = add nuw nsw i32 %37, 1
%39 = zext i32 %38 to i64
%40 = icmp ugt i64 %23, %39
br i1 %40, label %41, label %63
41: ; preds = %36, %56
%42 = phi i64 [ %61, %56 ], [ %39, %36 ]
%43 = phi i32 [ %60, %56 ], [ %38, %36 ]
%44 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %42
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %63, label %47
47: ; preds = %41
%48 = call i64 @strncmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %63
50: ; preds = %47
%51 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %63, label %53
53: ; preds = %50
%54 = call i64 @strncmp(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%55 = icmp eq i64 %54, 0
br i1 %55, label %63, label %56
56: ; preds = %53
%57 = call i64 @strlen(i8* %44)
%58 = trunc i64 %57 to i32
%59 = add i32 %43, %58
%60 = add nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = icmp ugt i64 %23, %61
br i1 %62, label %41, label %63
63: ; preds = %56, %50, %53, %41, %47, %36, %25
%64 = phi i32 [ 0, %25 ], [ 0, %36 ], [ 0, %56 ], [ 0, %50 ], [ 1, %53 ], [ 0, %41 ], [ 0, %47 ]
br label %65
65: ; preds = %14, %10, %63
%66 = phi i32 [ %64, %63 ], [ 0, %10 ], [ 0, %14 ]
br label %67
67: ; preds = %6, %1, %65
%68 = phi i32 [ %66, %65 ], [ 0, %1 ], [ 0, %6 ]
ret i32 %68
}