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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int sprintf(char *, char *, char *, ...);
scalar_t__ strstr(char *, char *);
void check_sip(char *buffer, uint32_t *pos, uint32_t max) {
  FILE *fp = NULL;
  char line[0x1000];
  (*pos) += sprintf(
      buffer + (*pos), "\nSystem Status:%s\n",
      "\n------------------------------------------------------------------");
  fp = popen("csrutil status", "r");
  while (fgets(line, sizeof(line), fp) != NULL) {
    if (strstr(line, "enabled")) {
      (*pos) += sprintf(buffer + (*pos),
                        "System Integrity Protection:\t%sENABLED%s\n",
                        "\x1b[31m", "\x1b[0m");
    } else {
      if (strstr(line, "disabled")) {
        (*pos) += sprintf(buffer + (*pos),
                          "System Integrity Protection:\t%sDISABLED%s\n",
                          "\x1b[32m", "\x1b[0m");
      } else {
        (*pos) += sprintf(buffer + (*pos),
                          "System Integrity Protection:\t%sUNKNOWN%s\n",
                          "\x1b[31m", "\x1b[0m");
      }
    }
  }
  pclose(fp);
}


x86 assembly (clang, -O0):
<check_sip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
lea    0xe7d(%rip),%rsi
lea    0xe89(%rip),%rdx
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
lea    0xeb5(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1000,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12bb <check_sip+0x16b>
lea    -0x1020(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1227 <check_sip+0xd7>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
lea    0xe6d(%rip),%rsi
lea    0xe90(%rip),%rdx
lea    0xe8f(%rip),%rcx
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
jmp    12b6 <check_sip+0x166>
lea    -0x1020(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     127d <check_sip+0x12d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
lea    0xe55(%rip),%rsi
lea    0xe79(%rip),%rdx
lea    0xe39(%rip),%rcx
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
jmp    12b1 <check_sip+0x161>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
lea    0xe4d(%rip),%rsi
lea    0xe01(%rip),%rdx
lea    0xe00(%rip),%rcx
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
jmp    12b6 <check_sip+0x166>
jmp    11b2 <check_sip+0x62>
mov    -0x20(%rbp),%rdi
call   1030 <pclose@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_sip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movslq (%rsi),%rdi
add    %r14,%rdi
lea    0xe8c(%rip),%rsi
lea    0xe98(%rip),%rdx
xor    %eax,%eax
call   1060 <sprintf@plt>
add    %eax,(%rbx)
lea    0xecc(%rip),%rdi
lea    0xed4(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1248 <check_sip+0xf8>
lea    0xeae(%rip),%r12
mov    %rsp,%r13
lea    0xedc(%rip),%rbp
jmp    1205 <check_sip+0xb5>
cs nopw 0x0(%rax,%rax,1)
movslq (%rbx),%rdi
add    %r14,%rdi
lea    0xe93(%rip),%rsi
lea    0xeb6(%rip),%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <sprintf@plt>
add    %eax,(%rbx)
mov    %r13,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1248 <check_sip+0xf8>
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
jne    11d0 <check_sip+0x80>
mov    %r13,%rdi
lea    0xe86(%rip),%rsi
call   1070 <strstr@plt>
movslq (%rbx),%rdi
add    %r14,%rdi
test   %rax,%rax
je     123f <check_sip+0xef>
lea    0xe78(%rip),%rsi
lea    0xe9c(%rip),%rdx
jmp    11e4 <check_sip+0x94>
lea    0xe99(%rip),%rsi
jmp    11dd <check_sip+0x8d>
mov    %r15,%rdi
call   1030 <pclose@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"\0ASystem Status:%s\0A\00"
@.str.1 = [68 x i8] c"\0A------------------------------------------------------------------\00"
@.str.2 = [15 x i8] c"csrutil status\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [8 x i8] c"enabled\00"
@.str.5 = [42 x i8] c"System Integrity Protection:\09%sENABLED%s\0A\00"
@.str.6 = [6 x i8] c"\1B[31m\00"
@.str.7 = [5 x i8] c"\1B[0m\00"
@.str.8 = [9 x i8] c"disabled\00"
@.str.9 = [43 x i8] c"System Integrity Protection:\09%sDISABLED%s\0A\00"
@.str.10 = [6 x i8] c"\1B[32m\00"
@.str.11 = [42 x i8] c"System Integrity Protection:\09%sUNKNOWN%s\0A\00"
define void @check_sip(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [4096 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32* null, i32** %7
%9 = load i8*, i8** %4
%10 = load i32*, i32** %5
%11 = load i32, i32* %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = add nsw i32 %16, %14
store i32 %17, i32* %15
%18 = call i32* @popen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %18, i32** %7
br label %19
19: ; preds = %63, %3
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%21 = load i32*, i32** %7
%22 = call i32* @fgets(i8* %20, i32 4096, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %64
24: ; preds = %19
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%26 = call i64 @strstr(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load i8*, i8** %4
%30 = load i32*, i32** %5
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%35 = load i32*, i32** %5
%36 = load i32, i32* %35
%37 = add nsw i32 %36, %34
store i32 %37, i32* %35
br label %63
38: ; preds = %24
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%40 = call i64 @strstr(i8* %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i8*, i8** %4
%44 = load i32*, i32** %5
%45 = load i32, i32* %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
%48 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %47, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%49 = load i32*, i32** %5
%50 = load i32, i32* %49
%51 = add nsw i32 %50, %48
store i32 %51, i32* %49
br label %62
52: ; preds = %38
%53 = load i8*, i8** %4
%54 = load i32*, i32** %5
%55 = load i32, i32* %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
%58 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%59 = load i32*, i32** %5
%60 = load i32, i32* %59
%61 = add nsw i32 %60, %58
store i32 %61, i32* %59
br label %62
62: ; preds = %52, %42
br label %63
63: ; preds = %62, %28
br label %19
64: ; preds = %19
%65 = load i32*, i32** %7
%66 = call i32 @pclose(i32* %65)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"\0ASystem Status:%s\0A\00"
@.str.1 = [68 x i8] c"\0A------------------------------------------------------------------\00"
@.str.2 = [15 x i8] c"csrutil status\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [8 x i8] c"enabled\00"
@.str.5 = [42 x i8] c"System Integrity Protection:\09%sENABLED%s\0A\00"
@.str.6 = [6 x i8] c"\1B[31m\00"
@.str.7 = [5 x i8] c"\1B[0m\00"
@.str.8 = [9 x i8] c"disabled\00"
@.str.9 = [43 x i8] c"System Integrity Protection:\09%sDISABLED%s\0A\00"
@.str.10 = [6 x i8] c"\1B[32m\00"
@.str.11 = [42 x i8] c"System Integrity Protection:\09%sUNKNOWN%s\0A\00"
define void @check_sip(i8* nocapture writeonly %0, i32* nocapture %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* %1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = add nsw i32 %10, %9
store i32 %11, i32* %1
%12 = tail call i32* @popen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32* @fgets(i8* %5, i32 4096, i32* %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %39, label %15
15: ; preds = %3, %33
%16 = call i64 @strstr(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %21, i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %33
23: ; preds = %15
%24 = call i64 @strstr(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
%26 = load i32, i32* %1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
br i1 %25, label %31, label %29
29: ; preds = %23
%30 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %28, i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %33
31: ; preds = %23
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %28, i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %33
33: ; preds = %29, %31, %18
%34 = phi i32 [ %30, %29 ], [ %32, %31 ], [ %22, %18 ]
%35 = load i32, i32* %1
%36 = add nsw i32 %35, %34
store i32 %36, i32* %1
%37 = call i32* @fgets(i8* %5, i32 4096, i32* %12)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %15
39: ; preds = %33, %3
%40 = call i32 @pclose(i32* %12)
ret void
}