#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ syscall(int, int, long, int, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int putchar(int ch) {
  static char buf[64] __attribute__((aligned(64)));
  static int buflen = 0;
  buf[buflen++] = ch;
  if (ch == '\n' || buflen == sizeof(buf)) {
    syscall(64, 1, (long)buf, buflen, 0, 0);
    buflen = 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<putchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %al,%dl
mov    0x2f9a(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2f8f(%rip)
movslq %eax,%rcx
lea    0x2f45(%rip),%rax
mov    %dl,(%rax,%rcx,1)
cmpl   $0xa,-0x4(%rbp)
je     1159 <putchar+0x49>
movslq 0x2f71(%rip),%rax
cmp    $0x40,%rax
jne    1185 <putchar+0x75>
mov    0x2f61(%rip),%ecx
mov    $0x40,%edi
mov    $0x1,%esi
lea    0x2f10(%rip),%rdx
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1030 <syscall@plt>
movl   $0x0,0x2f3b(%rip)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putchar>:
push   %rax
movslq 0x2fa8(%rip),%rax
lea    0x1(%rax),%ecx
mov    %ecx,0x2f9f(%rip)
lea    0x2f58(%rip),%rdx
mov    %dil,(%rax,%rdx,1)
cmp    $0xa,%edi
je     1136 <putchar+0x26>
cmp    $0x40,%ecx
jne    115c <putchar+0x4c>
lea    0x2f43(%rip),%rdx
mov    $0x40,%edi
mov    $0x1,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <syscall@plt>
movl   $0x0,0x2f64(%rip)
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@putchar.buf = internal global [64 x i8] zeroinitializer
@putchar.buflen = internal global i32 0
define i32 @putchar(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = trunc i32 %3 to i8
%5 = load i32, i32* @putchar.buflen
%6 = add nsw i32 %5, 1
store i32 %6, i32* @putchar.buflen
%7 = sext i32 %5 to i64
%8 = getelementptr inbounds [64 x i8], [64 x i8]* @putchar.buf, i64 0, i64 %7
store i8 %4, i8* %8
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 10
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = load i32, i32* @putchar.buflen
%13 = sext i32 %12 to i64
%14 = icmp eq i64 %13, 64
br i1 %14, label %15, label %18
15: ; preds = %11, %1
%16 = load i32, i32* @putchar.buflen
%17 = call i32 @syscall(i32 64, i32 1, i64 ptrtoint ([64 x i8]* @putchar.buf to i64), i32 %16, i32 0, i32 0)
store i32 0, i32* @putchar.buflen
br label %18
18: ; preds = %15, %11
ret i32 0
}

LLVM IR (-O2):
@putchar.buf = internal global [64 x i8] zeroinitializer
@putchar.buflen = internal unnamed_addr global i32 0
define i32 @putchar(i32 %0) {
%2 = trunc i32 %0 to i8
%3 = load i32, i32* @putchar.buflen
%4 = add nsw i32 %3, 1
store i32 %4, i32* @putchar.buflen
%5 = sext i32 %3 to i64
%6 = getelementptr inbounds [64 x i8], [64 x i8]* @putchar.buf, i64 0, i64 %5
store i8 %2, i8* %6
%7 = icmp eq i32 %0, 10
%8 = icmp eq i32 %4, 64
%9 = select i1 %7, i1 true, i1 %8
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @syscall(i32 64, i32 1, i64 ptrtoint ([64 x i8]* @putchar.buf to i64), i32 %4, i32 0, i32 0)
store i32 0, i32* @putchar.buflen
br label %12
12: ; preds = %1, %10
ret i32 0
}