#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*/ memset(char *, char, unsigned int);
unsigned int fill_dummy(char *buf, unsigned int buf_size) {
  if (!buf || buf_size < 4) {
    return 0;
  }
  buf[0] = 'B';
  buf[1] = '\0';
  memset(buf + 2, 'D', buf_size - 3);
  buf[buf_size - 1] = '\0';
  return buf_size;
}


x86 assembly (clang, -O0):
<fill_dummy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1134 <fill_dummy+0x24>
cmpl   $0x4,-0x14(%rbp)
jae    1140 <fill_dummy+0x30>
movl   $0x0,-0x4(%rbp)
jmp    117d <fill_dummy+0x6d>
mov    -0x10(%rbp),%rax
movb   $0x42,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    -0x14(%rbp),%edx
sub    $0x3,%edx
mov    $0x44,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_dummy>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
test   %rdi,%rdi
je     1148 <fill_dummy+0x38>
mov    %esi,%r14d
cmp    $0x4,%esi
jb     1148 <fill_dummy+0x38>
mov    %rdi,%rbx
movw   $0x42,(%rdi)
add    $0x2,%rdi
lea    -0x3(%r14),%edx
mov    $0x44,%esi
call   1030 <memset@plt>
lea    -0x1(%r14),%eax
movb   $0x0,(%rbx,%rax,1)
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @fill_dummy(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %5
%10 = icmp ult i32 %9, 4
br i1 %10, label %11, label %12
11: ; preds = %8, %2
store i32 0, i32* %3
br label %28
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 66, i8* %14
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 0, i8* %16
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 2
%19 = load i32, i32* %5
%20 = sub i32 %19, 3
%21 = call i32 @memset(i8* %18, i8 signext 68, i32 %20)
%22 = load i8*, i8** %4
%23 = load i32, i32* %5
%24 = sub i32 %23, 1
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 0, i8* %26
%27 = load i32, i32* %5
store i32 %27, i32* %3
br label %28
28: ; preds = %12, %11
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @fill_dummy(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp ult i32 %1, 4
%5 = or i1 %3, %4
br i1 %5, label %14, label %6
6: ; preds = %2
store i8 66, i8* %0
%7 = getelementptr inbounds i8, i8* %0, i64 1
store i8 0, i8* %7
%8 = getelementptr inbounds i8, i8* %0, i64 2
%9 = add i32 %1, -3
%10 = tail call i32 @memset(i8* %8, i8 signext 68, i32 %9)
%11 = add i32 %1, -1
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 0, i8* %13
br label %14
14: ; preds = %2, %6
%15 = phi i32 [ %1, %6 ], [ 0, %2 ]
ret i32 %15
}