#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*/ _printf_pad(int, int, unsigned int, char *);
int /*<<< orphan*/ _printf_puts(char const *, char *);
int strlen(char const *);
int _printf_putn(const char *str, int width, unsigned int fillChar,
                 char *origBuf) {
  int len = strlen(str);
  char *buf = origBuf;
  buf += _printf_pad(-width, len, fillChar, buf);
  buf += _printf_puts(str, buf);
  buf += _printf_pad(width, len, fillChar, buf);
  return buf - origBuf;
}


x86 assembly (clang, -O0):
<_printf_putn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
xor    %edi,%edi
sub    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x28(%rbp),%rcx
call   1030 <_printf_pad@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <_printf_puts@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x28(%rbp),%rcx
call   1030 <_printf_pad@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_printf_putn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    %r15d,%edi
neg    %edi
mov    %eax,%esi
mov    %r14d,%edx
mov    %r12,%rcx
call   1030 <_printf_pad@plt>
movslq %eax,%rbx
add    %r12,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <_printf_puts@plt>
movslq %eax,%rbp
add    %rbx,%rbp
mov    %r15d,%edi
mov    %r13d,%esi
mov    %r14d,%edx
mov    %rbp,%rcx
call   1030 <_printf_pad@plt>
add    %ebp,%eax
sub    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_printf_putn(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
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 = call i32 @strlen(i8* %11)
store i32 %12, i32* %9
%13 = load i8*, i8** %8
store i8* %13, i8** %10
%14 = load i32, i32* %6
%15 = sub nsw i32 0, %14
%16 = load i32, i32* %9
%17 = load i32, i32* %7
%18 = load i8*, i8** %10
%19 = call i32 @_printf_pad(i32 %15, i32 %16, i32 %17, i8* %18)
%20 = load i8*, i8** %10
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8* %22, i8** %10
%23 = load i8*, i8** %5
%24 = load i8*, i8** %10
%25 = call i32 @_printf_puts(i8* %23, i8* %24)
%26 = load i8*, i8** %10
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8* %28, i8** %10
%29 = load i32, i32* %6
%30 = load i32, i32* %9
%31 = load i32, i32* %7
%32 = load i8*, i8** %10
%33 = call i32 @_printf_pad(i32 %29, i32 %30, i32 %31, i8* %32)
%34 = load i8*, i8** %10
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8* %36, i8** %10
%37 = load i8*, i8** %10
%38 = load i8*, i8** %8
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = trunc i64 %41 to i32
ret i32 %42
}

LLVM IR (-O2):
define i32 @_printf_putn(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = sub nsw i32 0, %1
%7 = tail call i32 @_printf_pad(i32 %6, i32 %5, i32 %2, i8* %3)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %3, i64 %8
%10 = tail call i32 @_printf_puts(i8* %0, i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = tail call i32 @_printf_pad(i32 %1, i32 %5, i32 %2, i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = ptrtoint i8* %15 to i64
%17 = ptrtoint i8* %3 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
ret i32 %19
}