#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*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
void print_result(char *buffer) {
  FILE *current_fd = stdout;
  for (unsigned long i = 0; buffer[i] != '\0'; i++) {
    if (buffer[i] == '\f')
      current_fd = (current_fd == stdout) ? stderr : stdout;
    else
      fputc(buffer[i], current_fd);
  }
}


x86 assembly (clang, -O0):
<print_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11cb <print_result+0xbb>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xc,%eax
jne    119e <print_result+0x8e>
mov    -0x10(%rbp),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
jne    1183 <print_result+0x73>
mov    0x2e69(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1191 <print_result+0x81>
mov    0x2e4e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11b5 <print_result+0xa5>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
jmp    11ba <print_result+0xaa>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1132 <print_result+0x22>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_result>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eb6(%rip),%r15
mov    (%r15),%r14
mov    0x2eb4(%rip),%r12
jmp    1137 <print_result+0x27>
xchg   %ax,%ax
add    $0x1,%rbx
mov    %rax,%r14
movzbl (%rbx),%eax
cmp    $0xc,%al
je     1160 <print_result+0x50>
test   %al,%al
je     116e <print_result+0x5e>
movsbl %al,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbx
jmp    1137 <print_result+0x27>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%rax
cmp    %rax,%r14
jne    1130 <print_result+0x20>
mov    (%r12),%rax
jmp    1130 <print_result+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32* null
@stderr = global i32* null
define void @print_result(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i32*, i32** @stdout
store i32* %5, i32** %3
store i64 0, i64* %4
br label %6
6: ; preds = %38, %1
%7 = load i8*, i8** %2
%8 = load i64, i64* %4
%9 = getelementptr inbounds i8, i8* %7, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %41
13: ; preds = %6
%14 = load i8*, i8** %2
%15 = load i64, i64* %4
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 12
br i1 %19, label %20, label %30
20: ; preds = %13
%21 = load i32*, i32** %3
%22 = load i32*, i32** @stdout
%23 = icmp eq i32* %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = load i32*, i32** @stderr
br label %28
26: ; preds = %20
%27 = load i32*, i32** @stdout
br label %28
28: ; preds = %26, %24
%29 = phi i32* [ %25, %24 ], [ %27, %26 ]
store i32* %29, i32** %3
br label %37
30: ; preds = %13
%31 = load i8*, i8** %2
%32 = load i64, i64* %4
%33 = getelementptr inbounds i8, i8* %31, i64 %32
%34 = load i8, i8* %33
%35 = load i32*, i32** %3
%36 = call i32 @fputc(i8 signext %34, i32* %35)
br label %37
37: ; preds = %30, %28
br label %38
38: ; preds = %37
%39 = load i64, i64* %4
%40 = add i64 %39, 1
store i64 %40, i64* %4
br label %6
41: ; preds = %6
ret void
}

LLVM IR (-O2):
@stdout = global i32* null
@stderr = global i32* null
define void @print_result(i8* nocapture %0) {
%2 = load i32*, i32** @stdout
br label %3
3: ; preds = %16, %1
%4 = phi i32* [ %2, %1 ], [ %17, %16 ]
%5 = phi i64 [ 0, %1 ], [ %18, %16 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %14 [
i8 0, label %8
i8 12, label %9
]
8: ; preds = %3
ret void
9: ; preds = %3
%10 = load i32*, i32** @stdout
%11 = icmp eq i32* %4, %10
%12 = load i32*, i32** @stderr
%13 = select i1 %11, i32* %12, i32* %10
br label %16
14: ; preds = %3
%15 = tail call i32 @fputc(i8 signext %7, i32* %4)
br label %16
16: ; preds = %9, %14
%17 = phi i32* [ %13, %9 ], [ %4, %14 ]
%18 = add i64 %5, 1
br label %3
}