#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_byte(char);
void write_bytecounted_string(unsigned bytecount, char *s) {
  while (*s != 0 && bytecount != 0) {
    write_byte(*s++);
    bytecount--;
  }
  while (bytecount != 0) {
    write_byte(' ');
    bytecount--;
  }
}


x86 assembly (clang, -O0):
<write_bytecounted_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     113e <write_bytecounted_string+0x2e>
cmpl   $0x0,-0x4(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    114e <write_bytecounted_string+0x3e>
jmp    1173 <write_bytecounted_string+0x63>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <write_byte@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    111f <write_bytecounted_string+0xf>
jmp    1178 <write_bytecounted_string+0x68>
cmpl   $0x0,-0x4(%rbp)
je     119a <write_bytecounted_string+0x8a>
mov    $0x20,%edi
call   1030 <write_byte@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1178 <write_bytecounted_string+0x68>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_bytecounted_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    (%rsi),%al
test   %al,%al
je     1150 <write_bytecounted_string+0x40>
test   %ebp,%ebp
je     1150 <write_bytecounted_string+0x40>
mov    %rsi,%r14
mov    %ebp,%r15d
add    $0xffffffffffffffff,%r15
xor    %ebx,%ebx
nop
movsbl %al,%edi
call   1030 <write_byte@plt>
movzbl 0x1(%r14,%rbx,1),%eax
lea    0x1(%rbx),%rcx
test   %al,%al
je     114e <write_bytecounted_string+0x3e>
cmp    %ebx,%r15d
mov    %rcx,%rbx
jne    1130 <write_bytecounted_string+0x20>
sub    %ecx,%ebp
test   %ebp,%ebp
je     116f <write_bytecounted_string+0x5f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x20,%edi
call   1030 <write_byte@plt>
add    $0xffffffff,%ebp
jne    1160 <write_bytecounted_string+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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