#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ write(int, char *, int);
int fillout(char ch, int k) {
  char buf[32];
  memset(buf, ch, sizeof(buf));
  while (k > sizeof(buf)) {
    write(2, buf, sizeof(buf));
    k -= sizeof(buf);
  }
  if (k > 0)
    write(2, buf, k);
  return (0);
}


x86 assembly (clang, -O0):
<fillout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x1(%rbp),%al
movsbl %al,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
movslq -0x8(%rbp),%rax
cmp    $0x20,%rax
jbe    1176 <fillout+0x56>
lea    -0x30(%rbp),%rsi
mov    $0x2,%edi
mov    $0x20,%edx
call   1030 <write@plt>
movslq -0x8(%rbp),%rax
sub    $0x20,%rax
mov    %eax,-0x8(%rbp)
jmp    1145 <fillout+0x25>
cmpl   $0x0,-0x8(%rbp)
jle    1191 <fillout+0x71>
lea    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    $0x2,%edi
call   1030 <write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillout>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %edi,%esi
mov    %rsp,%rdi
mov    $0x20,%edx
call   1040 <memset@plt>
cmp    $0x21,%ebx
jb     115c <fillout+0x3c>
mov    %rsp,%r14
mov    $0x2,%edi
mov    %r14,%rsi
mov    $0x20,%edx
call   1030 <write@plt>
add    $0xffffffe0,%ebx
cmp    $0x20,%ebx
ja     1140 <fillout+0x20>
jmp    1160 <fillout+0x40>
test   %ebx,%ebx
je     116f <fillout+0x4f>
mov    %rsp,%rsi
mov    $0x2,%edi
mov    %ebx,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @fillout(i8 signext %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca [32 x i8]
store i8 %0, i8* %3
store i32 %1, i32* %4
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%7 = load i8, i8* %3
%8 = call i32 @memset(i8* %6, i8 signext %7, i32 32)
br label %9
9: ; preds = %13, %2
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = icmp ugt i64 %11, 32
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%15 = call i32 @write(i32 2, i8* %14, i32 32)
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = sub i64 %17, 32
%19 = trunc i64 %18 to i32
store i32 %19, i32* %4
br label %9
20: ; preds = %9
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%25 = load i32, i32* %4
%26 = call i32 @write(i32 2, i8* %24, i32 %25)
br label %27
27: ; preds = %23, %20
ret i32 0
}

LLVM IR (-O2):
define i32 @fillout(i8 signext %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i8 signext %0, i32 32)
%6 = icmp ugt i32 %1, 32
br i1 %6, label %7, label %12
7: ; preds = %2, %7
%8 = phi i32 [ %10, %7 ], [ %1, %2 ]
%9 = call i32 @write(i32 2, i8* %4, i32 32)
%10 = add i32 %8, -32
%11 = icmp ugt i32 %10, 32
br i1 %11, label %7, label %14
12: ; preds = %2
%13 = icmp eq i32 %1, 0
br i1 %13, label %17, label %14
14: ; preds = %7, %12
%15 = phi i32 [ %1, %12 ], [ %10, %7 ]
%16 = call i32 @write(i32 2, i8* %4, i32 %15)
br label %17
17: ; preds = %14, %12
ret i32 0
}