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


x86 assembly (clang, -O0):
<write_bytecounted_string_as_big_endian_unicode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     115c <write_bytecounted_string_as_big_endian_unicode+0x3c>
cmpl   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116c <write_bytecounted_string_as_big_endian_unicode+0x4c>
jmp    1191 <write_bytecounted_string_as_big_endian_unicode+0x71>
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    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    113d <write_bytecounted_string_as_big_endian_unicode+0x1d>
jmp    1196 <write_bytecounted_string_as_big_endian_unicode+0x76>
cmpl   $0x0,-0x18(%rbp)
je     11b7 <write_bytecounted_string_as_big_endian_unicode+0x97>
movsbl -0x11(%rbp),%edi
call   1030 <write_big_endian_word@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1196 <write_bytecounted_string_as_big_endian_unicode+0x76>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11cf <write_bytecounted_string_as_big_endian_unicode+0xaf>
movsbl -0x11(%rbp),%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   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %edi,%r15d
mov    %edi,%ebp
shr    %ebp
mov    (%rsi),%al
test   %al,%al
je     1183 <write_bytecounted_string_as_big_endian_unicode+0x63>
cmp    $0x2,%r15d
jb     1183 <write_bytecounted_string_as_big_endian_unicode+0x63>
mov    %rsi,%r12
mov    %r15d,%ebp
mov    %rbp,%r13
shr    %r13
add    $0xffffffffffffffff,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <write_big_endian_word@plt>
movzbl 0x1(%r12,%rbx,1),%eax
lea    0x1(%rbx),%rcx
test   %al,%al
je     117e <write_bytecounted_string_as_big_endian_unicode+0x5e>
cmp    %ebx,%r13d
mov    %rcx,%rbx
jne    1160 <write_bytecounted_string_as_big_endian_unicode+0x40>
shr    %rbp
sub    %ecx,%ebp
test   %ebp,%ebp
je     119c <write_bytecounted_string_as_big_endian_unicode+0x7c>
movsbl %r14b,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <write_big_endian_word@plt>
add    $0xffffffff,%ebp
jne    1190 <write_bytecounted_string_as_big_endian_unicode+0x70>
test   $0x1,%r15b
jne    11b1 <write_bytecounted_string_as_big_endian_unicode+0x91>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movsbl %r14b,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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, i8 signext %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%8 = load i32, i32* %4
%9 = udiv i32 %8, 2
store i32 %9, i32* %7
br label %10
10: ; preds = %20, %3
%11 = load i8*, i8** %5
%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 = %10
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br label %18
18: ; preds = %15, %10
%19 = phi i1 [ false, %10 ], [ %17, %15 ]
br i1 %19, label %20, label %27
20: ; preds = %18
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %5
%23 = load i8, i8* %21
%24 = call i32 @write_big_endian_word(i8 signext %23)
%25 = load i32, i32* %7
%26 = add i32 %25, -1
store i32 %26, i32* %7
br label %10
27: ; preds = %18
br label %28
28: ; preds = %31, %27
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i8, i8* %6
%33 = call i32 @write_big_endian_word(i8 signext %32)
%34 = load i32, i32* %7
%35 = add i32 %34, -1
store i32 %35, i32* %7
br label %28
36: ; preds = %28
%37 = load i32, i32* %4
%38 = urem i32 %37, 2
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i8, i8* %6
%42 = call i32 @write_byte(i8 signext %41)
br label %43
43: ; preds = %40, %36
ret void
}

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