#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, int /*<<< orphan*/ *);
int write_chars_bin(FILE *out, char *s, int count) {
  int t;
  for (t = 0; t < count; t++)
    if (fputc(s[t], out) == EOF)
      return -1;
  return 0;
}


x86 assembly (clang, -O0):
<write_chars_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    117c <write_chars_bin+0x6c>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    0x2e94(%rip),%rcx
cmp    (%rcx),%rax
jne    1169 <write_chars_bin+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <write_chars_bin+0x73>
jmp    116e <write_chars_bin+0x5e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <write_chars_bin+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_chars_bin>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
jle    114c <write_chars_bin+0x3c>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
mov    0x2eb9(%rip),%r13
nop
movsbl (%r14,%rbx,1),%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
cmp    0x0(%r13),%rax
je     1150 <write_chars_bin+0x40>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <write_chars_bin+0x20>
xor    %eax,%eax
jmp    1155 <write_chars_bin+0x45>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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