#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*/ fwrite(char const *, int /*<<< orphan*/, int,
                          int /*<<< orphan*/);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char const *);
void write_stdout(const char *str, int end) {
  if (end < 0)
    end = 0;
  while (end--)
    putc('\b', stdout);
  if (str != NULL)
    fwrite(str, strlen(str), 1, stdout);
}


x86 assembly (clang, -O0):
<write_stdout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1150 <write_stdout+0x20>
movl   $0x0,-0xc(%rbp)
jmp    1155 <write_stdout+0x25>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1181 <write_stdout+0x51>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edi
call   1040 <putc@plt>
jmp    1155 <write_stdout+0x25>
cmpq   $0x0,-0x8(%rbp)
je     11b6 <write_stdout+0x86>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
mov    0x2e36(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1050 <fwrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_stdout>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
test   %esi,%esi
jle    1161 <write_stdout+0x31>
mov    %esi,%ebp
mov    0x2e9c(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx),%esi
mov    $0x8,%edi
call   1040 <putc@plt>
add    $0xffffffff,%ebp
jne    1150 <write_stdout+0x20>
test   %r14,%r14
je     118a <write_stdout+0x5a>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%ecx
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x1,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <fwrite@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define void @write_stdout(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %2
store i32 0, i32* %4
br label %8
8: ; preds = %7, %2
br label %9
9: ; preds = %13, %8
%10 = load i32, i32* %4
%11 = add nsw i32 %10, -1
store i32 %11, i32* %4
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stdout
%15 = call i32 @putc(i8 signext 8, i32 %14)
br label %9
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load i8*, i8** %3
%22 = call i32 @strlen(i8* %21)
%23 = load i32, i32* @stdout
%24 = call i32 @fwrite(i8* %20, i32 %22, i32 1, i32 %23)
br label %25
25: ; preds = %19, %16
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @write_stdout(i8* %0, i32 %1) {
%3 = icmp slt i32 %1, 1
br i1 %3, label %10, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %6, %4 ], [ %1, %2 ]
%6 = add nsw i32 %5, -1
%7 = load i32, i32* @stdout
%8 = tail call i32 @putc(i8 signext 8, i32 %7)
%9 = icmp eq i32 %6, 0
br i1 %9, label %10, label %4
10: ; preds = %4, %2
%11 = icmp eq i8* %0, null
br i1 %11, label %16, label %12
12: ; preds = %10
%13 = tail call i32 @strlen(i8* %0)
%14 = load i32, i32* @stdout
%15 = tail call i32 @fwrite(i8* %0, i32 %13, i32 1, i32 %14)
br label %16
16: ; preds = %12, %10
ret void
}