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


x86 assembly (clang, -O0):
<write_bytecounted_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x12(%rbp)
je     1143 <write_bytecounted_string+0x33>
cmpl   $0x0,-0x4(%rbp)
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    1153 <write_bytecounted_string+0x43>
jmp    1178 <write_bytecounted_string+0x68>
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    1124 <write_bytecounted_string+0x14>
jmp    117d <write_bytecounted_string+0x6d>
cmpl   $0x0,-0x4(%rbp)
je     119e <write_bytecounted_string+0x8e>
movsbl -0x11(%rbp),%edi
call   1030 <write_byte@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    117d <write_bytecounted_string+0x6d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_bytecounted_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %edi,%ebx
mov    (%rsi),%al
test   %al,%al
je     1160 <write_bytecounted_string+0x50>
test   %ebx,%ebx
je     1160 <write_bytecounted_string+0x50>
mov    %rsi,%r15
mov    %ebx,%r12d
add    $0xffffffffffffffff,%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <write_byte@plt>
movzbl 0x1(%r15,%rbp,1),%eax
lea    0x1(%rbp),%rcx
test   %al,%al
je     115e <write_bytecounted_string+0x4e>
cmp    %ebp,%r12d
mov    %rcx,%rbp
jne    1140 <write_bytecounted_string+0x30>
sub    %ecx,%ebx
test   %ebx,%ebx
je     117c <write_bytecounted_string+0x6c>
movsbl %r14b,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <write_byte@plt>
add    $0xffffffff,%ebx
jne    1170 <write_bytecounted_string+0x60>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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