#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*/ console_putchar(char);
int /*<<< orphan*/ hal_write(int, char const *, int);
int strlen(char const *);
void format_output_str(const char *value, int align, int w, char pad) {
  if (!value)
    return;
  int len = strlen(value);
  int n_pad = w - len;
  if (align == 1) {
    while (n_pad-- > 0) {
      console_putchar(pad);
    }
  }
  hal_write(1, value, len);
  while (n_pad-- > 0) {
    console_putchar(pad);
  }
}


x86 assembly (clang, -O0):
<format_output_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1157 <format_output_str+0x27>
jmp    11d5 <format_output_str+0xa5>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11a2 <format_output_str+0x72>
jmp    117b <format_output_str+0x4b>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
jle    119d <format_output_str+0x6d>
movsbl -0x11(%rbp),%edi
call   1050 <console_putchar@plt>
jmp    117b <format_output_str+0x4b>
jmp    11a2 <format_output_str+0x72>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1040 <hal_write@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11d5 <format_output_str+0xa5>
movsbl -0x11(%rbp),%edi
call   1050 <console_putchar@plt>
jmp    11b3 <format_output_str+0x83>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_output_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11df <format_output_str+0xaf>
mov    %ecx,%ebx
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r12d,%ebp
sub    %eax,%ebp
cmp    $0x1,%r13d
jne    11a9 <format_output_str+0x79>
test   %ebp,%ebp
jle    118b <format_output_str+0x5b>
mov    %ebx,%eax
mov    %r15d,%ebx
sub    %r12d,%ebx
movsbl %al,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1050 <console_putchar@plt>
inc    %ebx
jne    1180 <format_output_str+0x50>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <hal_write@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <hal_write@plt>
test   %ebp,%ebp
jle    11df <format_output_str+0xaf>
add    $0x1,%ebp
movsbl %bl,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
call   1050 <console_putchar@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     11d0 <format_output_str+0xa0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @format_output_str(i8* %0, i32 %1, i32 %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8 %3, i8* %8
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %4
br label %42
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %9
%17 = load i32, i32* %7
%18 = load i32, i32* %9
%19 = sub nsw i32 %17, %18
store i32 %19, i32* %10
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %31
22: ; preds = %14
br label %23
23: ; preds = %27, %22
%24 = load i32, i32* %10
%25 = add nsw i32 %24, -1
store i32 %25, i32* %10
%26 = icmp sgt i32 %24, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8, i8* %8
%29 = call i32 @console_putchar(i8 signext %28)
br label %23
30: ; preds = %23
br label %31
31: ; preds = %30, %14
%32 = load i8*, i8** %5
%33 = load i32, i32* %9
%34 = call i32 @hal_write(i32 1, i8* %32, i32 %33)
br label %35
35: ; preds = %39, %31
%36 = load i32, i32* %10
%37 = add nsw i32 %36, -1
store i32 %37, i32* %10
%38 = icmp sgt i32 %36, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i8, i8* %8
%41 = call i32 @console_putchar(i8 signext %40)
br label %35
42: ; preds = %13, %35
ret void
}

LLVM IR (-O2):
define void @format_output_str(i8* %0, i32 %1, i32 %2, i8 signext %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %27, label %6
6: ; preds = %4
%7 = tail call i32 @strlen(i8* %0)
%8 = sub nsw i32 %2, %7
%9 = icmp eq i32 %1, 1
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = icmp sgt i32 %8, 0
br i1 %11, label %12, label %17
12: ; preds = %10, %12
%13 = phi i32 [ %14, %12 ], [ %8, %10 ]
%14 = add nsw i32 %13, -1
%15 = tail call i32 @console_putchar(i8 signext %3)
%16 = icmp eq i32 %14, 0
br i1 %16, label %17, label %12
17: ; preds = %12, %10
%18 = tail call i32 @hal_write(i32 1, i8* %0, i32 %7)
br label %27
19: ; preds = %6
%20 = tail call i32 @hal_write(i32 1, i8* %0, i32 %7)
%21 = icmp sgt i32 %8, 0
br i1 %21, label %22, label %27
22: ; preds = %19, %22
%23 = phi i32 [ %24, %22 ], [ %8, %19 ]
%24 = add nsw i32 %23, -1
%25 = tail call i32 @console_putchar(i8 signext %3)
%26 = icmp ugt i32 %23, 1
br i1 %26, label %22, label %27
27: ; preds = %22, %17, %19, %4
ret void
}