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

/* Variables and functions */
int /*<<< orphan*/ die(char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(char const *, int, int, int /*<<< orphan*/ *);
scalar_t__ strcmp(char const *, char *);
int strlen(char const *);
char *tracecmd_get_tracing_file(char *);
int /*<<< orphan*/ tracecmd_put_tracing_file(char *);
void old_update_events(const char *name, char update) {
  char *path;
  FILE *fp;
  int ret;
  if (strcmp(name, "all") == 0)
    name = "*:*";
  path = tracecmd_get_tracing_file("set_event");
  fp = fopen(path, "w");
  if (!fp)
    die("opening '%s'", path);
  tracecmd_put_tracing_file(path);
  if (update == '0')
    fwrite("!", 1, 1, fp);
  ret = fwrite(name, 1, strlen(name), fp);
  if (ret < 0)
    die("bad event '%s'", name);
  ret = fwrite("\n", 1, 1, fp);
  if (ret < 0)
    die("bad event '%s'", name);
  fclose(fp);
  return;
}


x86 assembly (clang, -O0):
<old_update_events>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11b7 <old_update_events+0x37>
lea    0xe51(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xe4a(%rip),%rdi
call   1060 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f6 <old_update_events+0x76>
mov    -0x18(%rbp),%rsi
lea    0xe23(%rip),%rdi
call   1090 <die@plt>
mov    -0x18(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jne    1223 <old_update_events+0xa3>
mov    -0x20(%rbp),%rcx
lea    0xe0a(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1265 <old_update_events+0xe5>
mov    -0x8(%rbp),%rsi
lea    0xdc3(%rip),%rdi
call   1090 <die@plt>
mov    -0x20(%rbp),%rcx
lea    0xdc2(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1299 <old_update_events+0x119>
mov    -0x8(%rbp),%rsi
lea    0xd8f(%rip),%rdi
call   1090 <die@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<old_update_events>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xe5c(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
lea    0xe51(%rip),%r14
cmovne %rbx,%r14
lea    0xe4a(%rip),%rdi
call   1070 <tracecmd_get_tracing_file@plt>
mov    %rax,%rbp
lea    0xe45(%rip),%rsi
mov    %rax,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ec <old_update_events+0x5c>
lea    0xe30(%rip),%rdi
mov    %rbp,%rsi
call   10a0 <die@plt>
mov    %rbp,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
cmp    $0x30,%r15b
jne    1207 <old_update_events+0x77>
mov    $0x21,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
test   %eax,%eax
jns    1234 <old_update_events+0xa4>
lea    0xdf5(%rip),%rdi
mov    %r14,%rsi
call   10a0 <die@plt>
lea    0xdf5(%rip),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
test   %eax,%eax
jns    1260 <old_update_events+0xd0>
lea    0xdc9(%rip),%rdi
mov    %r14,%rsi
call   10a0 <die@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"all\00"
@.str.1 = [4 x i8] c"*:*\00"
@.str.2 = [10 x i8] c"set_event\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [13 x i8] c"opening '%s'\00"
@.str.5 = [2 x i8] c"!\00"
@.str.6 = [15 x i8] c"bad event '%s'\00"
@.str.7 = [2 x i8] c"\0A\00"
define void @old_update_events(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
%8 = load i8*, i8** %3
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %12
12: ; preds = %11, %2
%13 = call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = call i32 @die(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %12
%22 = load i8*, i8** %5
%23 = call i32 @tracecmd_put_tracing_file(i8* %22)
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 48
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32*, i32** %6
%29 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1, i32 1, i32* %28)
br label %30
30: ; preds = %27, %21
%31 = load i8*, i8** %3
%32 = load i8*, i8** %3
%33 = call i32 @strlen(i8* %32)
%34 = load i32*, i32** %6
%35 = call i32 @fwrite(i8* %31, i32 1, i32 %33, i32* %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i8*, i8** %3
%40 = call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %30
%42 = load i32*, i32** %6
%43 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 1, i32 1, i32* %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i8*, i8** %3
%48 = call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %41
%50 = load i32*, i32** %6
%51 = call i32 @fclose(i32* %50)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"all\00"
@.str.1 = [4 x i8] c"*:*\00"
@.str.2 = [10 x i8] c"set_event\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [13 x i8] c"opening '%s'\00"
@.str.6 = [15 x i8] c"bad event '%s'\00"
@.str.7 = [2 x i8] c"\0A\00"
define void @old_update_events(i8* %0, i8 signext %1) {
%3 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %0
%6 = tail call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @die(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %11
11: ; preds = %9, %2
%12 = tail call i32 @tracecmd_put_tracing_file(i8* %6)
%13 = icmp eq i8 %1, 48
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @fputc(i32 33, i32* %7)
br label %16
16: ; preds = %14, %11
%17 = tail call i32 @strlen(i8* %5)
%18 = tail call i32 @fwrite(i8* %5, i32 1, i32 %17, i32* %7)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %5)
br label %22
22: ; preds = %20, %16
%23 = tail call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 1, i32 1, i32* %7)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %5)
br label %27
27: ; preds = %25, %22
%28 = tail call i32 @fclose(i32* %7)
ret void
}