#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*/ die(char *, char *);
char *malloc_or_die(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *,
                           char const *);
scalar_t__ strlen(char const *);
char *strtok(char *, char *);
char *tracecmd_get_tracing_file(char *);
int /*<<< orphan*/ tracecmd_put_tracing_file(char *);
char *get_event_file(const char *type, char *buf, int len) {
  char *system;
  char *event;
  char *path;
  char *file;
  if (buf[len - 1] == '\n')
    buf[len - 1] = '\0';
  system = strtok(buf, ":");
  if (!system)
    die("no system found in %s", buf);
  event = strtok(NULL, ":");
  if (!event)
    die("no event found in %s\n", buf);
  path = tracecmd_get_tracing_file("events");
  file = malloc_or_die(strlen(path) + strlen(system) + strlen(event) +
                       strlen(type) + strlen("///") + 1);
  sprintf(file, "%s/%s/%s/%s", path, system, event, type);
  tracecmd_put_tracing_file(path);
  return file;
}


x86 assembly (clang, -O0):
<get_event_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11ae <get_event_file+0x3e>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11dd <get_event_file+0x6d>
mov    -0x10(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1070 <die@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe18(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    120c <get_event_file+0x9c>
mov    -0x10(%rbp),%rsi
lea    0xe11(%rip),%rdi
call   1070 <die@plt>
lea    0xe1b(%rip),%rdi
call   1050 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
lea    0xdc0(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc_or_die@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x8(%rbp),%r9
lea    0xd90(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
mov    -0x38(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_event_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,0x10(%rsp)
movslq %edx,%rax
cmpb   $0xa,-0x1(%rax,%rsi,1)
jne    1195 <get_event_file+0x25>
movb   $0x0,-0x1(%rbx,%rax,1)
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11bb <get_event_file+0x4b>
lea    0xe4f(%rip),%rdi
mov    %rbx,%rsi
call   1070 <die@plt>
lea    0xe3e(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11e0 <get_event_file+0x70>
lea    0xe40(%rip),%rdi
mov    %rbx,%rsi
call   1070 <die@plt>
lea    0xe47(%rip),%rdi
call   1050 <tracecmd_get_tracing_file@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r14,0x8(%rsp)
mov    %rax,%r14
mov    0x10(%rsp),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %r13,%rbp
add    %r14,%rbp
lea    (%rax,%rbp,1),%rdi
add    $0x4,%rdi
call   1060 <malloc_or_die@plt>
mov    %rax,%rbp
lea    0xdf6(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    0x8(%rsp),%rcx
mov    %r12,%r8
mov    %r15,%r9
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
@.str.1 = [22 x i8] c"no system found in %s\00"
@.str.2 = [22 x i8] c"no event found in %s\0A\00"
@.str.3 = [7 x i8] c"events\00"
@.str.4 = [4 x i8] c"///\00"
@.str.5 = [12 x i8] c"%s/%s/%s/%s\00"
define i8* @get_event_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %25
19: ; preds = %3
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %19, %3
%26 = load i8*, i8** %5
%27 = call i8* @strtok(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %33, label %30
30: ; preds = %25
%31 = load i8*, i8** %5
%32 = call i32 @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %30, %25
%34 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %34, i8** %8
%35 = load i8*, i8** %8
%36 = icmp ne i8* %35, null
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = load i8*, i8** %5
%39 = call i32 @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %33
%41 = call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = call i64 @strlen(i8* %42)
%44 = load i8*, i8** %7
%45 = call i64 @strlen(i8* %44)
%46 = add nsw i64 %43, %45
%47 = load i8*, i8** %8
%48 = call i64 @strlen(i8* %47)
%49 = add nsw i64 %46, %48
%50 = load i8*, i8** %4
%51 = call i64 @strlen(i8* %50)
%52 = add nsw i64 %49, %51
%53 = call i64 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%54 = add nsw i64 %52, %53
%55 = add nsw i64 %54, 1
%56 = call i8* @malloc_or_die(i64 %55)
store i8* %56, i8** %10
%57 = load i8*, i8** %10
%58 = load i8*, i8** %9
%59 = load i8*, i8** %7
%60 = load i8*, i8** %8
%61 = load i8*, i8** %4
%62 = call i32 @sprintf(i8* %57, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %58, i8* %59, i8* %60, i8* %61)
%63 = load i8*, i8** %9
%64 = call i32 @tracecmd_put_tracing_file(i8* %63)
%65 = load i8*, i8** %10
ret i8* %65
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
@.str.1 = [22 x i8] c"no system found in %s\00"
@.str.2 = [22 x i8] c"no event found in %s\0A\00"
@.str.3 = [7 x i8] c"events\00"
@.str.5 = [12 x i8] c"%s/%s/%s/%s\00"
define i8* @get_event_file(i8* %0, i8* %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 10
br i1 %8, label %9, label %10
9: ; preds = %3
store i8 0, i8* %6
br label %10
10: ; preds = %9, %3
%11 = tail call i8* @strtok(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %15
15: ; preds = %13, %10
%16 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %20
20: ; preds = %18, %15
%21 = tail call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%22 = tail call i64 @strlen(i8* dereferenceable(1) %21)
%23 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%24 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%25 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%26 = add i64 %22, 4
%27 = add i64 %26, %23
%28 = add i64 %27, %24
%29 = add i64 %28, %25
%30 = tail call i8* @malloc_or_die(i64 %29)
%31 = tail call i32 @sprintf(i8* dereferenceable(1) %30, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %21, i8* %11, i8* %16, i8* %0)
%32 = tail call i32 @tracecmd_put_tracing_file(i8* %21)
ret i8* %30
}