#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*/ write_big_endian_word(char);
int /*<<< orphan*/ write_byte(char);
void write_bytecounted_string_as_big_endian_unicode(unsigned bytecount,
                                                    char *s) {
  unsigned wordcount = bytecount / 2;
  while (*s != 0 && wordcount != 0) {
    write_big_endian_word(*s++);
    wordcount--;
  }
  while (wordcount != 0) {
    write_big_endian_word(' ');
    wordcount--;
  }
  if (bytecount % 2 != 0)
    write_byte(' ');
}


x86 assembly (clang, -O0):
<write_bytecounted_string_as_big_endian_unicode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     1157 <write_bytecounted_string_as_big_endian_unicode+0x37>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1167 <write_bytecounted_string_as_big_endian_unicode+0x47>
jmp    118c <write_bytecounted_string_as_big_endian_unicode+0x6c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <write_big_endian_word@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1138 <write_bytecounted_string_as_big_endian_unicode+0x18>
jmp    1191 <write_bytecounted_string_as_big_endian_unicode+0x71>
cmpl   $0x0,-0x14(%rbp)
je     11b3 <write_bytecounted_string_as_big_endian_unicode+0x93>
mov    $0x20,%edi
call   1030 <write_big_endian_word@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1191 <write_bytecounted_string_as_big_endian_unicode+0x71>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11cc <write_bytecounted_string_as_big_endian_unicode+0xac>
mov    $0x20,%edi
call   1040 <write_byte@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_bytecounted_string_as_big_endian_unicode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
mov    %edi,%ebp
shr    %ebp
mov    (%rsi),%al
test   %al,%al
je     1173 <write_bytecounted_string_as_big_endian_unicode+0x53>
cmp    $0x2,%r14d
jb     1173 <write_bytecounted_string_as_big_endian_unicode+0x53>
mov    %rsi,%r15
mov    %r14d,%ebp
mov    %rbp,%r12
shr    %r12
add    $0xffffffffffffffff,%r12
xor    %ebx,%ebx
nopl   (%rax)
movsbl %al,%edi
call   1030 <write_big_endian_word@plt>
movzbl 0x1(%r15,%rbx,1),%eax
lea    0x1(%rbx),%rcx
test   %al,%al
je     116e <write_bytecounted_string_as_big_endian_unicode+0x4e>
cmp    %ebx,%r12d
mov    %rcx,%rbx
jne    1150 <write_bytecounted_string_as_big_endian_unicode+0x30>
shr    %rbp
sub    %ecx,%ebp
test   %ebp,%ebp
je     118f <write_bytecounted_string_as_big_endian_unicode+0x6f>
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <write_big_endian_word@plt>
add    $0xffffffff,%ebp
jne    1180 <write_bytecounted_string_as_big_endian_unicode+0x60>
test   $0x1,%r14b
jne    119e <write_bytecounted_string_as_big_endian_unicode+0x7e>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x20,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <write_byte@plt>

LLVM IR (-O0):
define void @write_bytecounted_string_as_big_endian_unicode(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = udiv i32 %6, 2
store i32 %7, i32* %5
br label %8
8: ; preds = %18, %2
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br label %16
16: ; preds = %13, %8
%17 = phi i1 [ false, %8 ], [ %15, %13 ]
br i1 %17, label %18, label %25
18: ; preds = %16
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
%21 = load i8, i8* %19
%22 = call i32 @write_big_endian_word(i8 signext %21)
%23 = load i32, i32* %5
%24 = add i32 %23, -1
store i32 %24, i32* %5
br label %8
25: ; preds = %16
br label %26
26: ; preds = %29, %25
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = call i32 @write_big_endian_word(i8 signext 32)
%31 = load i32, i32* %5
%32 = add i32 %31, -1
store i32 %32, i32* %5
br label %26
33: ; preds = %26
%34 = load i32, i32* %3
%35 = urem i32 %34, 2
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @write_byte(i8 signext 32)
br label %39
39: ; preds = %37, %33
ret void
}

LLVM IR (-O2):
define void @write_bytecounted_string_as_big_endian_unicode(i32 %0, i8* nocapture %1) {
%3 = lshr i32 %0, 1
%4 = load i8, i8* %1
%5 = icmp ne i8 %4, 0
%6 = icmp ugt i32 %0, 1
%7 = and i1 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %11, %2
%9 = phi i32 [ %3, %2 ], [ %17, %11 ]
%10 = icmp eq i32 %9, 0
br i1 %10, label %27, label %22
11: ; preds = %2, %11
%12 = phi i8 [ %18, %11 ], [ %4, %2 ]
%13 = phi i32 [ %17, %11 ], [ %3, %2 ]
%14 = phi i8* [ %15, %11 ], [ %1, %2 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = tail call i32 @write_big_endian_word(i8 signext %12)
%17 = add nsw i32 %13, -1
%18 = load i8, i8* %15
%19 = icmp ne i8 %18, 0
%20 = icmp ne i32 %17, 0
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %11, label %8
22: ; preds = %8, %22
%23 = phi i32 [ %25, %22 ], [ %9, %8 ]
%24 = tail call i32 @write_big_endian_word(i8 signext 32)
%25 = add i32 %23, -1
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %22
27: ; preds = %22, %8
%28 = and i32 %0, 1
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @write_byte(i8 signext 32)
br label %32
32: ; preds = %30, %27
ret void
}