#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*/ vbuf;

/* Variables and functions */
short atoi(char *);
char *getenv(char *);
int /*<<< orphan*/ strcmp(char const *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
int testSubsystem(short level, const char *subsys) {
  char *cp;
  char vbuf[128];
  static short trace_level = -1;
  static char *trace_subsys = 0;
  if (trace_level == -1) {
    trace_subsys = getenv("TRACE_SUBSYS");
    if ((cp = getenv("TRACE_LEVEL")) != NULL) {
      trace_level = atoi(cp);
    } else {
      trace_level = 0;
    }
  }
  if (trace_level < level) {
    return 0;
  }
  if (!trace_subsys) {
    return 1;
  }
  strncpy(vbuf, trace_subsys, sizeof(vbuf));
  vbuf[sizeof(vbuf) - 1] = '\0';
  for (cp = strtok(vbuf, ","); cp != NULL; cp = strtok(NULL, ",")) {
    if (!strcmp(subsys, cp)) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<testSubsystem>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %di,%ax
mov    %ax,-0x6(%rbp)
mov    %rsi,-0x10(%rbp)
movswl 0x2edb(%rip),%eax
cmp    $0xffffffff,%eax
jne    11c6 <testSubsystem+0x76>
lea    0xe83(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ecf(%rip)
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11b8 <testSubsystem+0x68>
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %ax,0x2e95(%rip)
jmp    11c1 <testSubsystem+0x71>
movw   $0x0,0x2e87(%rip)
jmp    11c6 <testSubsystem+0x76>
movswl 0x2e7b(%rip),%eax
movswl -0x6(%rbp),%ecx
cmp    %ecx,%eax
jge    11e5 <testSubsystem+0x95>
movl   $0x0,-0x4(%rbp)
jmp    1284 <testSubsystem+0x134>
cmpq   $0x0,0x2e6b(%rip)
jne    11ff <testSubsystem+0xaf>
movl   $0x1,-0x4(%rbp)
jmp    1284 <testSubsystem+0x134>
lea    -0xa0(%rbp),%rdi
mov    0x2e4b(%rip),%rsi
mov    $0x80,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x21(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     127d <testSubsystem+0x12d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    125f <testSubsystem+0x10f>
movl   $0x1,-0x4(%rbp)
jmp    1284 <testSubsystem+0x134>
jmp    1264 <testSubsystem+0x114>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdaa(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1232 <testSubsystem+0xe2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testSubsystem>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movzwl 0x2ee1(%rip),%eax
cmp    $0xffff,%ax
jne    11a4 <testSubsystem+0x54>
lea    0xe8c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ed8(%rip)
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     119b <testSubsystem+0x4b>
mov    %rax,%rdi
call   1070 <atoi@plt>
jmp    119d <testSubsystem+0x4d>
xor    %eax,%eax
mov    %ax,0x2ea4(%rip)
xor    %ebx,%ebx
cmp    %bp,%ax
jl     1217 <testSubsystem+0xc7>
mov    0x2ea6(%rip),%rsi
test   %rsi,%rsi
je     1212 <testSubsystem+0xc2>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x80,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x7f(%rsp)
lea    0xe46(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     1217 <testSubsystem+0xc7>
lea    0xe32(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1212 <testSubsystem+0xc2>
xor    %ebx,%ebx
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    11f0 <testSubsystem+0xa0>
jmp    1217 <testSubsystem+0xc7>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@testSubsystem.trace_level = internal global i16 -1
@testSubsystem.trace_subsys = internal global i8* null
@.str = [13 x i8] c"TRACE_SUBSYS\00"
@.str.1 = [12 x i8] c"TRACE_LEVEL\00"
@.str.2 = [2 x i8] c",\00"
define i32 @testSubsystem(i16 signext %0, i8* %1) {
%3 = alloca i32
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [128 x i8]
store i16 %0, i16* %4
store i8* %1, i8** %5
%8 = load i16, i16* @testSubsystem.trace_level
%9 = sext i16 %8 to i32
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %20
11: ; preds = %2
%12 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** @testSubsystem.trace_subsys
%13 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = call signext i16 @atoi(i8* %16)
store i16 %17, i16* @testSubsystem.trace_level
br label %19
18: ; preds = %11
store i16 0, i16* @testSubsystem.trace_level
br label %19
19: ; preds = %18, %15
br label %20
20: ; preds = %19, %2
%21 = load i16, i16* @testSubsystem.trace_level
%22 = sext i16 %21 to i32
%23 = load i16, i16* %4
%24 = sext i16 %23 to i32
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 0, i32* %3
br label %51
27: ; preds = %20
%28 = load i8*, i8** @testSubsystem.trace_subsys
%29 = icmp ne i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %27
store i32 1, i32* %3
br label %51
31: ; preds = %27
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%33 = load i8*, i8** @testSubsystem.trace_subsys
%34 = call i32 @strncpy(i8* %32, i8* %33, i32 128)
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 127
store i8 0, i8* %35
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%37 = call i8* @strtok(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %37, i8** %6
br label %38
38: ; preds = %48, %31
%39 = load i8*, i8** %6
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = load i8*, i8** %5
%43 = load i8*, i8** %6
%44 = call i32 @strcmp(i8* %42, i8* %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %41
store i32 1, i32* %3
br label %51
47: ; preds = %41
br label %48
48: ; preds = %47
%49 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %49, i8** %6
br label %38
50: ; preds = %38
store i32 0, i32* %3
br label %51
51: ; preds = %50, %46, %30, %26
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@testSubsystem.trace_level = internal unnamed_addr global i16 -1
@testSubsystem.trace_subsys = internal unnamed_addr global i8* null
@.str = [13 x i8] c"TRACE_SUBSYS\00"
@.str.1 = [12 x i8] c"TRACE_LEVEL\00"
@.str.2 = [2 x i8] c",\00"
define i32 @testSubsystem(i16 signext %0, i8* nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = load i16, i16* @testSubsystem.trace_level
%6 = icmp eq i16 %5, -1
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** @testSubsystem.trace_subsys
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call signext i16 @atoi(i8* %9)
br label %13
13: ; preds = %7, %11
%14 = phi i16 [ %12, %11 ], [ 0, %7 ]
store i16 %14, i16* @testSubsystem.trace_level
br label %15
15: ; preds = %13, %2
%16 = phi i16 [ %5, %2 ], [ %14, %13 ]
%17 = icmp slt i16 %16, %0
br i1 %17, label %33, label %18
18: ; preds = %15
%19 = load i8*, i8** @testSubsystem.trace_subsys
%20 = icmp eq i8* %19, null
br i1 %20, label %33, label %21
21: ; preds = %18
%22 = call i32 @strncpy(i8* %4, i8* %19, i32 128)
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 127
store i8 0, i8* %23
%24 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %33, label %26
26: ; preds = %21, %30
%27 = phi i8* [ %31, %30 ], [ %24, %21 ]
%28 = call i32 @strcmp(i8* dereferenceable(1) %1, i8* %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %26
33: ; preds = %26, %30, %21, %18, %15
%34 = phi i32 [ 0, %15 ], [ 1, %18 ], [ 0, %21 ], [ 1, %26 ], [ 0, %30 ]
ret i32 %34
}