#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 FILENAME_MAX;
int /*<<< orphan*/ free(char *);
char *malloc(int);
int snprintf(char *, int, char *, char const *);
scalar_t__ trigger_glob(char *);
int trigger_subsystem(const char *subsystem) {
  int r, bytes;
  char *pattern;
  pattern = malloc(FILENAME_MAX);
  if (!pattern)
    return -1;
  r = 0;
  bytes = snprintf(pattern, FILENAME_MAX, "/sys/class/%s/*/uevent", subsystem);
  if (bytes < 0 || bytes >= FILENAME_MAX)
    r = -1;
  else if (trigger_glob(pattern) != 0)
    r = -1;
  bytes = snprintf(pattern, FILENAME_MAX, "/sys/bus/%s/devices/*/uevent",
                   subsystem);
  if (bytes < 0 || bytes >= FILENAME_MAX)
    r = -1;
  else if (trigger_glob(pattern) != 0)
    r = -1;
  if (pattern)
    free(pattern);
  return r;
}


x86 assembly (clang, -O0):
<trigger_subsystem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1175 <trigger_subsystem+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    1264 <trigger_subsystem+0x124>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
lea    0xe6c(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11b8 <trigger_subsystem+0x78>
mov    -0x18(%rbp),%eax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%eax
jl     11c4 <trigger_subsystem+0x84>
movl   $0xffffffff,-0x14(%rbp)
jmp    11e3 <trigger_subsystem+0xa3>
mov    -0x20(%rbp),%rdi
call   1040 <trigger_glob@plt>
cmp    $0x0,%rax
je     11de <trigger_subsystem+0x9e>
movl   $0xffffffff,-0x14(%rbp)
jmp    11e3 <trigger_subsystem+0xa3>
mov    -0x20(%rbp),%rdi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
lea    0xe1c(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     121f <trigger_subsystem+0xdf>
mov    -0x18(%rbp),%eax
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%eax
jl     122b <trigger_subsystem+0xeb>
movl   $0xffffffff,-0x14(%rbp)
jmp    124a <trigger_subsystem+0x10a>
mov    -0x20(%rbp),%rdi
call   1040 <trigger_glob@plt>
cmp    $0x0,%rax
je     1245 <trigger_subsystem+0x105>
movl   $0xffffffff,-0x14(%rbp)
jmp    124a <trigger_subsystem+0x10a>
cmpq   $0x0,-0x20(%rbp)
je     125e <trigger_subsystem+0x11e>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trigger_subsystem>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    0x2e96(%rip),%r15
mov    (%r15),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11d4 <trigger_subsystem+0x94>
mov    %rax,%rbx
lea    0xe95(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
mov    (%r15),%esi
mov    $0xffffffff,%ebp
mov    $0xffffffff,%r12d
test   %eax,%eax
js     119f <trigger_subsystem+0x5f>
cmp    %esi,%eax
jge    119f <trigger_subsystem+0x5f>
mov    %rbx,%rdi
call   1040 <trigger_glob@plt>
neg    %rax
sbb    %r12d,%r12d
mov    (%r15),%esi
lea    0xe71(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
call   1050 <snprintf@plt>
test   %eax,%eax
js     11ca <trigger_subsystem+0x8a>
cmp    (%r15),%eax
jge    11ca <trigger_subsystem+0x8a>
mov    %rbx,%rdi
call   1040 <trigger_glob@plt>
neg    %rax
sbb    %ebp,%ebp
or     %r12d,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11d9 <trigger_subsystem+0x99>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@.str = [23 x i8] c"/sys/class/%s/*/uevent\00"
@.str.1 = [29 x i8] c"/sys/bus/%s/devices/*/uevent\00"
define i32 @trigger_subsystem(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i32, i32* @FILENAME_MAX
%8 = call i8* @malloc(i32 %7)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i32 -1, i32* %2
br label %56
12: ; preds = %1
store i32 0, i32* %4
%13 = load i8*, i8** %6
%14 = load i32, i32* @FILENAME_MAX
%15 = load i8*, i8** %3
%16 = call i32 @snprintf(i8* %13, i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %12
%20 = load i32, i32* %5
%21 = load i32, i32* @FILENAME_MAX
%22 = icmp sge i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19, %12
store i32 -1, i32* %4
br label %30
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = call i64 @trigger_glob(i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 -1, i32* %4
br label %29
29: ; preds = %28, %24
br label %30
30: ; preds = %29, %23
%31 = load i8*, i8** %6
%32 = load i32, i32* @FILENAME_MAX
%33 = load i8*, i8** %3
%34 = call i32 @snprintf(i8* %31, i32 %32, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %33)
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = icmp slt i32 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %30
%38 = load i32, i32* %5
%39 = load i32, i32* @FILENAME_MAX
%40 = icmp sge i32 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %37, %30
store i32 -1, i32* %4
br label %48
42: ; preds = %37
%43 = load i8*, i8** %6
%44 = call i64 @trigger_glob(i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 -1, i32* %4
br label %47
47: ; preds = %46, %42
br label %48
48: ; preds = %47, %41
%49 = load i8*, i8** %6
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i8*, i8** %6
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %51, %48
%55 = load i32, i32* %4
store i32 %55, i32* %2
br label %56
56: ; preds = %54, %11
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@.str = [23 x i8] c"/sys/class/%s/*/uevent\00"
@.str.1 = [29 x i8] c"/sys/bus/%s/devices/*/uevent\00"
define i32 @trigger_subsystem(i8* %0) {
%2 = load i32, i32* @FILENAME_MAX
%3 = tail call i8* @malloc(i32 %2)
%4 = icmp eq i8* %3, null
br i1 %4, label %31, label %5
5: ; preds = %1
%6 = tail call i32 @snprintf(i8* %3, i32 %2, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = icmp sgt i32 %6, -1
%8 = load i32, i32* @FILENAME_MAX
%9 = icmp slt i32 %6, %8
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = tail call i64 @trigger_glob(i8* %3)
%13 = icmp ne i64 %12, 0
%14 = sext i1 %13 to i32
%15 = load i32, i32* @FILENAME_MAX
br label %16
16: ; preds = %11, %5
%17 = phi i32 [ %8, %5 ], [ %15, %11 ]
%18 = phi i32 [ -1, %5 ], [ %14, %11 ]
%19 = tail call i32 @snprintf(i8* %3, i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%20 = icmp sgt i32 %19, -1
%21 = load i32, i32* @FILENAME_MAX
%22 = icmp slt i32 %19, %21
%23 = select i1 %20, i1 %22, i1 false
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = tail call i64 @trigger_glob(i8* %3)
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i32 %18, i32 -1
br label %28
28: ; preds = %24, %16
%29 = phi i32 [ -1, %16 ], [ %27, %24 ]
%30 = tail call i32 @free(i8* %3)
br label %31
31: ; preds = %1, %28
%32 = phi i32 [ %29, %28 ], [ -1, %1 ]
ret i32 %32
}