#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 */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fputc_err(unsigned char, int /*<<< orphan*/ *);
void WritePaddedString(FILE *outf, char *str, unsigned long num,
                       unsigned char padding) {
  unsigned long ctr = 0;
  (assert(outf != NULL));
  if (num == 0)
    return;
  if (str != NULL)
    while (ctr < num) {
      if (str[ctr] == '\0')
        break;
      fputc_err(str[ctr++], outf);
    }
  while (ctr < num) {
    fputc_err(padding, outf);
    ctr++;
  }
}


x86 assembly (clang, -O0):
<WritePaddedString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1163 <WritePaddedString+0x43>
jmp    11fa <WritePaddedString+0xda>
cmpq   $0x0,-0x10(%rbp)
je     11c7 <WritePaddedString+0xa7>
jmp    1173 <WritePaddedString+0x53>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11c2 <WritePaddedString+0xa2>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    119b <WritePaddedString+0x7b>
jmp    11c2 <WritePaddedString+0xa2>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1040 <fputc_err@plt>
jmp    1173 <WritePaddedString+0x53>
jmp    11c7 <WritePaddedString+0xa7>
jmp    11cc <WritePaddedString+0xac>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11fa <WritePaddedString+0xda>
mov    -0x19(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1040 <fputc_err@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11cc <WritePaddedString+0xac>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WritePaddedString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
test   %rbx,%rbx
je     1190 <WritePaddedString+0x70>
xor    %ebp,%ebp
test   %r12,%r12
je     116f <WritePaddedString+0x4f>
xchg   %ax,%ax
movzbl (%r12,%rbp,1),%eax
test   %al,%al
je     116f <WritePaddedString+0x4f>
add    $0x1,%rbp
movzbl %al,%edi
mov    %r14,%rsi
call   1040 <fputc_err@plt>
cmp    %rbp,%rbx
jne    1150 <WritePaddedString+0x30>
jmp    1190 <WritePaddedString+0x70>
cmp    %rbx,%rbp
jae    1190 <WritePaddedString+0x70>
sub    %rbp,%rbx
movzbl %r15b,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <fputc_err@plt>
add    $0xffffffffffffffff,%rbx
jne    1180 <WritePaddedString+0x60>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @WritePaddedString(i32* %0, i8* %1, i64 %2, i8 zeroext %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8
%9 = alloca i64
store i32* %0, i32** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i8 %3, i8* %8
store i64 0, i64* %9
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i64, i64* %7
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
br label %53
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %42
20: ; preds = %17
br label %21
21: ; preds = %33, %20
%22 = load i64, i64* %9
%23 = load i64, i64* %7
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %41
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = load i64, i64* %9
%28 = getelementptr inbounds i8, i8* %26, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
br label %41
33: ; preds = %25
%34 = load i8*, i8** %6
%35 = load i64, i64* %9
%36 = add i64 %35, 1
store i64 %36, i64* %9
%37 = getelementptr inbounds i8, i8* %34, i64 %35
%38 = load i8, i8* %37
%39 = load i32*, i32** %5
%40 = call i32 @fputc_err(i8 zeroext %38, i32* %39)
br label %21
41: ; preds = %32, %21
br label %42
42: ; preds = %41, %17
br label %43
43: ; preds = %47, %42
%44 = load i64, i64* %9
%45 = load i64, i64* %7
%46 = icmp ult i64 %44, %45
br i1 %46, label %47, label %53
47: ; preds = %43
%48 = load i8, i8* %8
%49 = load i32*, i32** %5
%50 = call i32 @fputc_err(i8 zeroext %48, i32* %49)
%51 = load i64, i64* %9
%52 = add i64 %51, 1
store i64 %52, i64* %9
br label %43
53: ; preds = %16, %43
ret void
}

LLVM IR (-O2):
define void @WritePaddedString(i32* %0, i8* %1, i64 %2, i8 zeroext %3) {
%5 = icmp ne i32* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp eq i64 %2, 0
br i1 %8, label %28, label %9
9: ; preds = %4
%10 = icmp eq i8* %1, null
br i1 %10, label %20, label %11
11: ; preds = %9, %16
%12 = phi i64 [ %17, %16 ], [ 0, %9 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = add nuw i64 %12, 1
%18 = tail call i32 @fputc_err(i8 zeroext %14, i32* %0)
%19 = icmp eq i64 %17, %2
br i1 %19, label %28, label %11
20: ; preds = %11, %9
%21 = phi i64 [ 0, %9 ], [ %12, %11 ]
%22 = icmp ult i64 %21, %2
br i1 %22, label %23, label %28
23: ; preds = %20, %23
%24 = phi i64 [ %26, %23 ], [ %21, %20 ]
%25 = tail call i32 @fputc_err(i8 zeroext %3, i32* %0)
%26 = add i64 %24, 1
%27 = icmp eq i64 %26, %2
br i1 %27, label %28, label %23
28: ; preds = %16, %23, %20, %4
ret void
}