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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *strdup(char *);
char *strtok(char *, char *);
int wildcardcmp(char *, char const *);
int debug_is_enabled(const char *name) {
  char *env = NULL;
  char *tmp = NULL;
  char *debugger = NULL;
  int enabled = 0;
  if (!(env = getenv("DEBUG")))
    return 0;
  if (!(tmp = strdup(env)))
    return 0;
  debugger = strtok(tmp, ",");
  while (debugger) {
    if (1 == wildcardcmp(debugger, name)) {
      enabled = 1;
      break;
    }
    debugger = strtok(NULL, ",");
  }
  free(tmp);
  return enabled;
}


x86 assembly (clang, -O0):
<debug_is_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe7e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a1 <debug_is_enabled+0x51>
movl   $0x0,-0x4(%rbp)
jmp    1233 <debug_is_enabled+0xe3>
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c4 <debug_is_enabled+0x74>
movl   $0x0,-0x4(%rbp)
jmp    1233 <debug_is_enabled+0xe3>
mov    -0x20(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1224 <debug_is_enabled+0xd4>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <wildcardcmp@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    120b <debug_is_enabled+0xbb>
movl   $0x1,-0x2c(%rbp)
jmp    1224 <debug_is_enabled+0xd4>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdf0(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    11d8 <debug_is_enabled+0x88>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_is_enabled>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11d4 <debug_is_enabled+0x84>
mov    %rax,%rdi
call   1070 <strdup@plt>
test   %rax,%rax
je     11d4 <debug_is_enabled+0x84>
mov    %rax,%r14
lea    0xe81(%rip),%rsi
mov    %rax,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11c3 <debug_is_enabled+0x73>
lea    0xe6d(%rip),%r12
nopl   0x0(%rax)
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <wildcardcmp@plt>
cmp    $0x1,%eax
je     11c7 <debug_is_enabled+0x77>
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    11a0 <debug_is_enabled+0x50>
jmp    11cc <debug_is_enabled+0x7c>
xor    %ebx,%ebx
jmp    11cc <debug_is_enabled+0x7c>
mov    $0x1,%ebx
mov    %r14,%rdi
call   1040 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"DEBUG\00"
@.str.1 = [2 x i8] c",\00"
define i32 @debug_is_enabled(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %4
store i8* null, i8** %5
store i8* null, i8** %6
store i32 0, i32* %7
%8 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 0, i32* %2
br label %34
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %11
store i32 0, i32* %2
br label %34
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %6
br label %19
19: ; preds = %28, %16
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i8*, i8** %6
%24 = load i8*, i8** %3
%25 = call i32 @wildcardcmp(i8* %23, i8* %24)
%26 = icmp eq i32 1, %25
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 1, i32* %7
br label %30
28: ; preds = %22
%29 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %29, i8** %6
br label %19
30: ; preds = %27, %19
%31 = load i8*, i8** %5
%32 = call i32 @free(i8* %31)
%33 = load i32, i32* %7
store i32 %33, i32* %2
br label %34
34: ; preds = %30, %15, %10
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [6 x i8] c"DEBUG\00"
@.str.1 = [2 x i8] c",\00"
define i32 @debug_is_enabled(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %4
%8 = tail call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %17, label %10
10: ; preds = %7, %14
%11 = phi i8* [ %15, %14 ], [ %8, %7 ]
%12 = tail call i32 @wildcardcmp(i8* %11, i8* %0)
%13 = icmp eq i32 %12, 1
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %10
17: ; preds = %14, %10, %7
%18 = phi i32 [ 0, %7 ], [ 1, %10 ], [ 0, %14 ]
%19 = tail call i32 @free(i8* %5)
br label %20
20: ; preds = %4, %1, %17
%21 = phi i32 [ %18, %17 ], [ 0, %1 ], [ 0, %4 ]
ret i32 %21
}