#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 */
unsigned short fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ write_short(unsigned short, int /*<<< orphan*/ *);
int write_counted_string(unsigned short count, char *string, FILE *file) {
  if (write_short(count, file) == 0)
    return 0;
  if (fwrite(string, (int)sizeof(char), (int)count, file) != count)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<write_counted_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x6(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x6(%rbp),%ax
mov    -0x18(%rbp),%rsi
movzwl %ax,%edi
call   1030 <write_short@plt>
cmp    $0x0,%rax
jne    115d <write_counted_string+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    1195 <write_counted_string+0x75>
mov    -0x10(%rbp),%rdi
movzwl -0x6(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
movzwl %ax,%eax
movzwl -0x6(%rbp),%ecx
cmp    %ecx,%eax
je     118e <write_counted_string+0x6e>
movl   $0x0,-0x4(%rbp)
jmp    1195 <write_counted_string+0x75>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_counted_string>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rdx,%rsi
call   1030 <write_short@plt>
test   %rax,%rax
je     115a <write_counted_string+0x3a>
movzwl %bp,%ebp
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %bp,%cx
sete   %al
jmp    115c <write_counted_string+0x3c>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_counted_string(i16 zeroext %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i32*
store i16 %0, i16* %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%8 = load i16, i16* %5
%9 = load i32*, i32** %7
%10 = call i64 @write_short(i16 zeroext %8, i32* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 0, i32* %4
br label %25
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = load i16, i16* %5
%16 = zext i16 %15 to i32
%17 = load i32*, i32** %7
%18 = call zeroext i16 @fwrite(i8* %14, i32 1, i32 %16, i32* %17)
%19 = zext i16 %18 to i32
%20 = load i16, i16* %5
%21 = zext i16 %20 to i32
%22 = icmp ne i32 %19, %21
br i1 %22, label %23, label %24
23: ; preds = %13
store i32 0, i32* %4
br label %25
24: ; preds = %13
store i32 1, i32* %4
br label %25
25: ; preds = %24, %23, %12
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
define i32 @write_counted_string(i16 zeroext %0, i8* nocapture %1, i32* %2) {
%4 = tail call i64 @write_short(i16 zeroext %0, i32* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = zext i16 %0 to i32
%8 = tail call zeroext i16 @fwrite(i8* %1, i32 1, i32 %7, i32* %2)
%9 = icmp eq i16 %8, %0
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %6, %3
%12 = phi i32 [ 0, %3 ], [ %10, %6 ]
ret i32 %12
}