#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 */
scalar_t__ EOF;
scalar_t__ fputc(char const, int /*<<< orphan*/ *);
int write_chars(FILE *out, const char *s) {
  int t = 0;
  while (s[t] != 0 && t < 255)
    if (fputc(s[t++], out) == EOF)
      return -1;
  return 0;
}


x86 assembly (clang, -O0):
<write_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     114e <write_chars+0x3e>
cmpl   $0xff,-0x1c(%rbp)
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    115e <write_chars+0x4e>
jmp    11a0 <write_chars+0x90>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%rax
jne    119b <write_chars+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <write_chars+0x97>
jmp    1127 <write_chars+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_chars>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %rdi,%r15
xor    %r14d,%r14d
mov    0x2ebf(%rip),%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbx,1),%eax
test   %al,%al
je     115e <write_chars+0x4e>
cmp    $0xfe,%rbx
ja     115e <write_chars+0x4e>
add    $0x1,%rbx
movsbl %al,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
cmp    (%r12),%rax
jne    1130 <write_chars+0x20>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@EOF = global i64 0
define i32 @write_chars(i32* nocapture %0, i8* nocapture %1) {
br label %3
3: ; preds = %10, %2
%4 = phi i64 [ %11, %10 ], [ 0, %2 ]
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
%8 = icmp ult i64 %4, 255
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = add nuw nsw i64 %4, 1
%12 = tail call i64 @fputc(i8 signext %6, i32* %0)
%13 = load i64, i64* @EOF
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %3
15: ; preds = %3, %10
%16 = phi i32 [ -1, %10 ], [ 0, %3 ]
ret i32 %16
}