#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 *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char const *, int, int, int /*<<< orphan*/ *);
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
char *tracecmd_get_tracing_file(char *);
int /*<<< orphan*/ tracecmd_put_tracing_file(char *);
void set_plugin(const char *name) {
  FILE *fp;
  char *path;
  char zero = '0';
  path = tracecmd_get_tracing_file("current_tracer");
  fp = fopen(path, "w");
  if (!fp)
    die("writing to '%s'", path);
  tracecmd_put_tracing_file(path);
  fwrite(name, 1, strlen(name), fp);
  fclose(fp);
  if (strncmp(name, "function", 8) != 0)
    return;
  path = tracecmd_get_tracing_file("options/func_stack_trace");
  fp = fopen(path, "w");
  tracecmd_put_tracing_file(path);
  if (!fp)
    return;
  fwrite(&zero, 1, 1, fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<set_plugin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x30,-0x19(%rbp)
lea    0xe69(%rip),%rdi
call   1070 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cf <set_plugin+0x4f>
mov    -0x18(%rbp),%rsi
lea    0xe47(%rip),%rdi
call   1090 <die@plt>
mov    -0x18(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x8(%rbp),%rdi
lea    0xe10(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     122a <set_plugin+0xaa>
jmp    1284 <set_plugin+0x104>
lea    0xdf9(%rip),%rdi
call   1070 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdca(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1267 <set_plugin+0xe7>
jmp    1284 <set_plugin+0x104>
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_plugin>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe61(%rip),%rdi
call   1080 <tracecmd_get_tracing_file@plt>
mov    %rax,%r15
lea    0xe61(%rip),%rsi
mov    %rax,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11cd <set_plugin+0x3d>
lea    0xe4c(%rip),%rdi
mov    %r15,%rsi
call   10a0 <die@plt>
mov    %r15,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe23(%rip),%rsi
mov    %r14,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1216 <set_plugin+0x86>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe0d(%rip),%rdi
call   1080 <tracecmd_get_tracing_file@plt>
mov    %rax,%rbx
lea    0xde3(%rip),%rsi
mov    %rax,%rdi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
test   %r14,%r14
je     1210 <set_plugin+0x80>
mov    $0x30,%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <fclose@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"current_tracer\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [16 x i8] c"writing to '%s'\00"
@.str.3 = [9 x i8] c"function\00"
@.str.4 = [25 x i8] c"options/func_stack_trace\00"
define void @set_plugin(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8
store i8* %0, i8** %2
store i8 48, i8* %5
%6 = call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %11, %1
%15 = load i8*, i8** %4
%16 = call i32 @tracecmd_put_tracing_file(i8* %15)
%17 = load i8*, i8** %2
%18 = load i8*, i8** %2
%19 = call i32 @strlen(i8* %18)
%20 = load i32*, i32** %3
%21 = call i32 @fwrite(i8* %17, i32 1, i32 %19, i32* %20)
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
%24 = load i8*, i8** %2
%25 = call i64 @strncmp(i8* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %14
br label %42
28: ; preds = %14
%29 = call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store i8* %29, i8** %4
%30 = load i8*, i8** %4
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %3
%32 = load i8*, i8** %4
%33 = call i32 @tracecmd_put_tracing_file(i8* %32)
%34 = load i32*, i32** %3
%35 = icmp ne i32* %34, null
br i1 %35, label %37, label %36
36: ; preds = %28
br label %42
37: ; preds = %28
%38 = load i32*, i32** %3
%39 = call i32 @fwrite(i8* %5, i32 1, i32 1, i32* %38)
%40 = load i32*, i32** %3
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %37, %36, %27
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"current_tracer\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [16 x i8] c"writing to '%s'\00"
@.str.3 = [9 x i8] c"function\00"
@.str.4 = [25 x i8] c"options/func_stack_trace\00"
define void @set_plugin(i8* %0) {
%2 = tail call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %7
7: ; preds = %5, %1
%8 = tail call i32 @tracecmd_put_tracing_file(i8* %2)
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i32 @fwrite(i8* %0, i32 1, i32 %9, i32* %3)
%11 = tail call i32 @fclose(i32* %3)
%12 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %7
%15 = tail call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @tracecmd_put_tracing_file(i8* %15)
%18 = icmp eq i32* %16, null
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = tail call i32 @fputc(i32 48, i32* %16)
%21 = tail call i32 @fclose(i32* %16)
br label %22
22: ; preds = %14, %7, %19
ret void
}