#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*/ outfile;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ add_channel(char *);
int /*<<< orphan*/ create_filepath(char *, int, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
void print_out(char *channel, char *buf) {
  static char outfile[256];
  FILE *out = NULL;
  create_filepath(outfile, sizeof(outfile), channel, "out");
  if (channel && channel[0])
    add_channel(channel);
  if (!(out = fopen(outfile, "a")))
    return;
  if (channel && channel[0])
    add_channel(channel);
  fprintf(out, "%s\n", buf);
  fclose(out);
}


x86 assembly (clang, -O0):
<print_out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdx
lea    0x2eed(%rip),%rdi
mov    $0x100,%esi
lea    0xe81(%rip),%rcx
call   1040 <create_filepath@plt>
cmpq   $0x0,-0x8(%rbp)
je     11a8 <print_out+0x58>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a8 <print_out+0x58>
mov    -0x8(%rbp),%rdi
call   1060 <add_channel@plt>
lea    0x2eb1(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ce <print_out+0x7e>
jmp    120f <print_out+0xbf>
cmpq   $0x0,-0x8(%rbp)
je     11f2 <print_out+0xa2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f2 <print_out+0xa2>
mov    -0x8(%rbp),%rdi
call   1060 <add_channel@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe05(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_out>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x2efe(%rip),%rdi
lea    0xe97(%rip),%rcx
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <create_filepath@plt>
test   %rbx,%rbx
je     11b2 <print_out+0x62>
cmpb   $0x0,(%rbx)
je     1188 <print_out+0x38>
mov    %rbx,%rdi
call   1060 <add_channel@plt>
lea    0x2ed1(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ec <print_out+0x9c>
mov    %rax,%r15
cmpb   $0x0,(%rbx)
je     11cd <print_out+0x7d>
mov    %rbx,%rdi
call   1060 <add_channel@plt>
jmp    11cd <print_out+0x7d>
lea    0x2ea7(%rip),%rdi
lea    0xe44(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     11ec <print_out+0x9c>
lea    0xe32(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@print_out.outfile = internal global [256 x i8] zeroinitializer
@.str = [4 x i8] c"out\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @print_out(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32* null, i32** %5
%6 = load i8*, i8** %3
%7 = call i32 @create_filepath(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @print_out.outfile, i64 0, i64 0), i32 256, i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i8*, i8** %3
%18 = call i32 @add_channel(i8* %17)
br label %19
19: ; preds = %16, %10, %2
%20 = call i32* @fopen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @print_out.outfile, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %5
%21 = icmp ne i32* %20, null
br i1 %21, label %23, label %22
22: ; preds = %19
br label %41
23: ; preds = %19
%24 = load i8*, i8** %3
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i8*, i8** %3
%34 = call i32 @add_channel(i8* %33)
br label %35
35: ; preds = %32, %26, %23
%36 = load i32*, i32** %5
%37 = load i8*, i8** %4
%38 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32*, i32** %5
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %35, %22
ret void
}

LLVM IR (-O2):
@print_out.outfile = internal global [256 x i8] zeroinitializer
@.str = [4 x i8] c"out\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @print_out(i8* %0, i8* %1) {
%3 = tail call i32 @create_filepath(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @print_out.outfile, i64 0, i64 0), i32 256, i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %0, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @add_channel(i8* %0)
br label %10
10: ; preds = %8, %5
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @print_out.outfile, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %25, label %16
13: ; preds = %2
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @print_out.outfile, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %25, label %21
16: ; preds = %10
%17 = load i8, i8* %0
%18 = icmp eq i8 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @add_channel(i8* %0)
br label %21
21: ; preds = %13, %19, %16
%22 = phi i32* [ %11, %19 ], [ %11, %16 ], [ %14, %13 ]
%23 = tail call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%24 = tail call i32 @fclose(i32* %22)
br label %25
25: ; preds = %13, %10, %21
ret void
}