#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int fill_string(char *str, int n, const char *fill) {
  int i;
  for (i = 0; i < n && fill[i] != '\0'; i++) {
    str[i] = fill[i];
  }
  if (i == n) {
    fprintf(stderr, "Status line too short to fill with '%s'\n", fill);
    exit(1);
  }
  return i;
}


x86 assembly (clang, -O0):
<fill_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    1160 <fill_string+0x40>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1170 <fill_string+0x50>
jmp    1194 <fill_string+0x74>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113a <fill_string+0x1a>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11c3 <fill_string+0xa3>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe4c(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_string>:
push   %rax
test   %esi,%esi
jle    1163 <fill_string+0x43>
mov    %esi,%r8d
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movzbl (%rdx,%rax,1),%ecx
test   %cl,%cl
je     1165 <fill_string+0x45>
mov    %cl,(%rdi,%rax,1)
add    $0x1,%rax
cmp    %rax,%r8
jne    1130 <fill_string+0x10>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
xor    %eax,%eax
cmp    %esi,%eax
je     1144 <fill_string+0x24>
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Status line too short to fill with '%s'\0A\00"
define i32 @fill_string(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %7
br label %8
8: ; preds = %32, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br label %20
20: ; preds = %12, %8
%21 = phi i1 [ false, %8 ], [ %19, %12 ]
br i1 %21, label %22, label %35
22: ; preds = %20
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %4
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %22
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %8
35: ; preds = %20
%36 = load i32, i32* %7
%37 = load i32, i32* %5
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %6
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %35
%45 = load i32, i32* %7
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Status line too short to fill with '%s'\0A\00"
define i32 @fill_string(i8* nocapture writeonly %0, i32 %1, i8* %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %12
%8 = phi i64 [ 0, %5 ], [ %14, %12 ]
%9 = getelementptr inbounds i8, i8* %2, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %10, i8* %13
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %21, label %7
16: ; preds = %7
%17 = trunc i64 %8 to i32
br label %18
18: ; preds = %16, %3
%19 = phi i32 [ 0, %3 ], [ %17, %16 ]
%20 = icmp eq i32 %19, %1
br i1 %20, label %21, label %25
21: ; preds = %12, %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %2)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %18
ret i32 %19
}