#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 strlen(char *);
char *fillstrx(char *target, int len, char datachar) {
  int i;
  if (target == NULL)
    return NULL;
  for (i = strlen(target); i < len; i++)
    target[i] = datachar;
  target[len] = '\0';
  return target;
}


x86 assembly (clang, -O0):
<fillstrx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %al,-0x15(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113c <fillstrx+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    1184 <fillstrx+0x74>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1170 <fillstrx+0x60>
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <fillstrx+0x38>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillstrx>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     115e <fillstrx+0x3e>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %ebp,%eax
jge    1157 <fillstrx+0x37>
movslq %eax,%rdi
add    %rbx,%rdi
not    %eax
add    %ebp,%eax
add    $0x1,%rax
movzbl %r14b,%esi
mov    %rax,%rdx
call   1040 <memset@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @fillstrx(i8* %0, i32 %1, i8 signext %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp slt i32 %6, %1
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = sext i32 %6 to i64
%10 = getelementptr i8, i8* %0, i64 %9
%11 = xor i32 %6, -1
%12 = add i32 %11, %1
%13 = zext i32 %12 to i64
%14 = add nuw nsw i64 %13, 1
br label %15
15: ; preds = %8, %5
%16 = sext i32 %1 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %3, %15
ret i8* %0
}