#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int gl_pathc;
  char **gl_pathv;
  scalar_t__ gl_offs;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *, char *);
int glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ old_update_events(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
char *tracecmd_get_tracing_file(char *);
int /*<<< orphan*/ tracecmd_put_tracing_file(char *);
scalar_t__ use_old_event_method();
int write(int, char *, int);
void reset_events(void) {
  glob_t globbuf;
  char *path;
  char c;
  int fd;
  int i;
  int ret;
  if (use_old_event_method()) {
    old_update_events("all", '0');
    return;
  }
  c = '0';
  path = tracecmd_get_tracing_file("events/enable");
  fd = open(path, O_WRONLY);
  if (fd < 0)
    die("opening to '%s'", path);
  ret = write(fd, &c, 1);
  close(fd);
  tracecmd_put_tracing_file(path);
  path = tracecmd_get_tracing_file("events/*/filter");
  globbuf.gl_offs = 0;
  ret = glob(path, 0, NULL, &globbuf);
  tracecmd_put_tracing_file(path);
  if (ret < 0)
    return;
  for (i = 0; i < globbuf.gl_pathc; i++) {
    path = globbuf.gl_pathv[i];
    fd = open(path, O_WRONLY);
    if (fd < 0)
      die("opening to '%s'", path);
    ret = write(fd, &c, 1);
    close(fd);
  }
  globfree(&globbuf);
}


x86 assembly (clang, -O0):
<reset_events>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1040 <use_old_event_method@plt>
cmp    $0x0,%rax
je     11cf <reset_events+0x2f>
lea    0xe40(%rip),%rdi
mov    $0x30,%esi
call   1060 <old_update_events@plt>
jmp    1302 <reset_events+0x162>
movb   $0x30,-0x21(%rbp)
lea    0xe2a(%rip),%rdi
call   1090 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1212 <reset_events+0x72>
mov    -0x20(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   10b0 <die@plt>
mov    -0x28(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1070 <write@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
lea    0xde4(%rip),%rdi
call   1090 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x8(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   10c0 <glob@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
cmpl   $0x0,-0x30(%rbp)
jge    127d <reset_events+0xdd>
jmp    1302 <reset_events+0x162>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12f9 <reset_events+0x159>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    12cf <reset_events+0x12f>
mov    -0x20(%rbp),%rsi
lea    0xd48(%rip),%rdi
call   10b0 <die@plt>
mov    -0x28(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1070 <write@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1284 <reset_events+0xe4>
lea    -0x18(%rbp),%rdi
call   1050 <globfree@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset_events>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   1040 <use_old_event_method@plt>
test   %rax,%rax
je     11d9 <reset_events+0x39>
lea    0xe3f(%rip),%rdi
mov    $0x30,%esi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <old_update_events@plt>
movb   $0x30,0xf(%rsp)
lea    0xe1f(%rip),%rdi
call   1090 <tracecmd_get_tracing_file@plt>
mov    %rax,%rbx
mov    0x2de4(%rip),%r12
mov    (%r12),%esi
mov    %rax,%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1215 <reset_events+0x75>
lea    0xe05(%rip),%rdi
mov    %rbx,%rsi
call   10b0 <die@plt>
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1070 <write@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %rbx,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
lea    0xde6(%rip),%rdi
call   1090 <tracecmd_get_tracing_file@plt>
mov    %rax,%rbx
movq   $0x0,0x20(%rsp)
lea    0x10(%rsp),%rcx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <glob@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
test   %ebp,%ebp
js     12e6 <reset_events+0x146>
cmpl   $0x0,0x10(%rsp)
jle    12dc <reset_events+0x13c>
xor    %ebx,%ebx
lea    0xd96(%rip),%r14
lea    0xf(%rsp),%r15
jmp    12b4 <reset_events+0x114>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1070 <write@plt>
mov    %ebp,%edi
call   1080 <close@plt>
add    $0x1,%rbx
movslq 0x10(%rsp),%rax
cmp    %rax,%rbx
jge    12dc <reset_events+0x13c>
mov    0x18(%rsp),%rax
mov    (%rax,%rbx,8),%r13
mov    (%r12),%esi
mov    %r13,%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1290 <reset_events+0xf0>
mov    %r14,%rdi
mov    %r13,%rsi
call   10b0 <die@plt>
jmp    1290 <reset_events+0xf0>
lea    0x10(%rsp),%rdi
call   1050 <globfree@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i8**, i64 }
@.str = [4 x i8] c"all\00"
@.str.1 = [14 x i8] c"events/enable\00"
@O_WRONLY = global i32 0
@.str.2 = [16 x i8] c"opening to '%s'\00"
@.str.3 = [16 x i8] c"events/*/filter\00"
define void @reset_events() {
%1 = alloca %struct.TYPE_4__
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i64 (...) @use_old_event_method()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @old_update_events(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 48)
br label %68
11: ; preds = %0
store i8 48, i8* %3
%12 = call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = load i32, i32* @O_WRONLY
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i8*, i8** %2
%20 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %11
%22 = load i32, i32* %4
%23 = call i32 @write(i32 %22, i8* %3, i32 1)
store i32 %23, i32* %6
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
%26 = load i8*, i8** %2
%27 = call i32 @tracecmd_put_tracing_file(i8* %26)
%28 = call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i8* %28, i8** %2
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i32 0, i32 2
store i64 0, i64* %29
%30 = load i8*, i8** %2
%31 = call i32 @glob(i8* %30, i32 0, i32* null, %struct.TYPE_4__* %1)
store i32 %31, i32* %6
%32 = load i8*, i8** %2
%33 = call i32 @tracecmd_put_tracing_file(i8* %32)
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %21
br label %68
37: ; preds = %21
store i32 0, i32* %5
br label %38
38: ; preds = %63, %37
%39 = load i32, i32* %5
%40 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i32 0, i32 0
%41 = load i32, i32* %40
%42 = icmp slt i32 %39, %41
br i1 %42, label %43, label %66
43: ; preds = %38
%44 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i32 0, i32 1
%45 = load i8**, i8*** %44
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
store i8* %49, i8** %2
%50 = load i8*, i8** %2
%51 = load i32, i32* @O_WRONLY
%52 = call i32 @open(i8* %50, i32 %51)
store i32 %52, i32* %4
%53 = load i32, i32* %4
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %43
%56 = load i8*, i8** %2
%57 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %56)
br label %58
58: ; preds = %55, %43
%59 = load i32, i32* %4
%60 = call i32 @write(i32 %59, i8* %3, i32 1)
store i32 %60, i32* %6
%61 = load i32, i32* %4
%62 = call i32 @close(i32 %61)
br label %63
63: ; preds = %58
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
store i32 %65, i32* %5
br label %38
66: ; preds = %38
%67 = call i32 @globfree(%struct.TYPE_4__* %1)
br label %68
68: ; preds = %66, %36, %9
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i8**, i64 }
@.str = [4 x i8] c"all\00"
@.str.1 = [14 x i8] c"events/enable\00"
@O_WRONLY = global i32 0
@.str.2 = [16 x i8] c"opening to '%s'\00"
@.str.3 = [16 x i8] c"events/*/filter\00"
define void @reset_events() {
%1 = alloca %struct.TYPE_4__
%2 = alloca i8
%3 = bitcast %struct.TYPE_4__* %1 to i8*
%4 = tail call i64 (...) @use_old_event_method()
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 @old_update_events(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 48)
br label %49
8: ; preds = %0
store i8 48, i8* %2
%9 = tail call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @O_WRONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %15
15: ; preds = %13, %8
%16 = call i32 @write(i32 %11, i8* %2, i32 1)
%17 = tail call i32 @close(i32 %11)
%18 = tail call i32 @tracecmd_put_tracing_file(i8* %9)
%19 = tail call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 0, i32 2
store i64 0, i64* %20
%21 = call i32 @glob(i8* %19, i32 0, i32* null, %struct.TYPE_4__* %1)
%22 = call i32 @tracecmd_put_tracing_file(i8* %19)
%23 = icmp slt i32 %21, 0
br i1 %23, label %49, label %24
24: ; preds = %15
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 0, i32 0
%26 = load i32, i32* %25
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %47
28: ; preds = %24
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 0, i32 1
br label %30
30: ; preds = %28, %40
%31 = phi i64 [ 0, %28 ], [ %43, %40 ]
%32 = load i8**, i8*** %29
%33 = getelementptr inbounds i8*, i8** %32, i64 %31
%34 = load i8*, i8** %33
%35 = load i32, i32* @O_WRONLY
%36 = call i32 @open(i8* %34, i32 %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %30
%39 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %40
40: ; preds = %38, %30
%41 = call i32 @write(i32 %36, i8* %2, i32 1)
%42 = call i32 @close(i32 %36)
%43 = add nuw nsw i64 %31, 1
%44 = load i32, i32* %25
%45 = sext i32 %44 to i64
%46 = icmp slt i64 %43, %45
br i1 %46, label %30, label %47
47: ; preds = %40, %24
%48 = call i32 @globfree(%struct.TYPE_4__* %1)
br label %49
49: ; preds = %15, %47, %6
ret void
}