#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
size_t strlen(char const *);
void write_with_padding(FILE *fp, const char *str, size_t len) {
  unsigned int i;
  assert(fp != NULL);
  assert(str != NULL);
  fprintf(fp, "%s", str);
  for (i = 0; i < len - strlen(str); i++) {
    fprintf(fp, "%c", '\0');
  }
}


x86 assembly (clang, -O0):
<write_with_padding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
sub    %rdx,%rcx
cmp    %rcx,%rax
jae    11d6 <write_with_padding+0xa6>
mov    -0x8(%rbp),%rdi
lea    0xe44(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1185 <write_with_padding+0x55>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_with_padding>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1060 <assert@plt>
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1060 <assert@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fputs@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    %r14,%rax
je     11b2 <write_with_padding+0x72>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    %ebp,%ebx
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %r14,%rcx
sub    %rax,%rcx
add    $0x1,%ebp
cmp    %rbx,%rcx
ja     1190 <write_with_padding+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%c\00"
define void @write_with_padding(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32*, i32** %4
%17 = load i8*, i8** %5
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 0, i32* %7
br label %19
19: ; preds = %30, %3
%20 = load i32, i32* %7
%21 = zext i32 %20 to i64
%22 = load i64, i64* %6
%23 = load i8*, i8** %5
%24 = call i64 @strlen(i8* %23)
%25 = sub i64 %22, %24
%26 = icmp ult i64 %21, %25
br i1 %26, label %27, label %33
27: ; preds = %19
%28 = load i32*, i32** %4
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %30
30: ; preds = %27
%31 = load i32, i32* %7
%32 = add i32 %31, 1
store i32 %32, i32* %7
br label %19
33: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @write_with_padding(i32* %0, i8* %1, i64 %2) {
%4 = icmp ne i32* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ne i8* %1, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @fputs(i8* %1, i32* %0)
%11 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%12 = icmp eq i64 %11, %2
br i1 %12, label %21, label %13
13: ; preds = %3, %13
%14 = phi i32 [ %16, %13 ], [ 0, %3 ]
%15 = tail call i32 @fputc(i32 0, i32* %0)
%16 = add i32 %14, 1
%17 = zext i32 %16 to i64
%18 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%19 = sub i64 %2, %18
%20 = icmp ugt i64 %19, %17
br i1 %20, label %13, label %21
21: ; preds = %13, %3
ret void
}