#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ freeipmi_memset(char *, char, unsigned int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, unsigned int);
int debug_set_prefix(char *buf, unsigned int buflen, const char *prefix) {
  assert(buf && buflen > 3);
  freeipmi_memset(buf, '\0', buflen);
  if (prefix) {
    strncpy(buf, prefix, buflen);
    buf[buflen - 1] = '\0';
    buf[buflen - 2] = '\0';
    buf[buflen - 3] = '\0';
    strcat(buf, ": ");
  }
  return (0);
}


x86 assembly (clang, -O0):
<debug_set_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
je     116d <debug_set_prefix+0x2d>
cmpl   $0x3,-0xc(%rbp)
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1040 <freeipmi_memset@plt>
cmpq   $0x0,-0x18(%rbp)
je     11e3 <debug_set_prefix+0xa3>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x3,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1060 <strcat@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_set_prefix>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
test   %rdi,%rdi
setne  %al
cmp    $0x4,%esi
setae  %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <freeipmi_memset@plt>
test   %r15,%r15
je     11a8 <debug_set_prefix+0x68>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
lea    -0x1(%rbx),%eax
movb   $0x0,(%r14,%rax,1)
lea    -0x2(%rbx),%eax
movb   $0x0,(%r14,%rax,1)
add    $0xfffffffd,%ebx
movb   $0x0,(%r14,%rbx,1)
lea    0xe60(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c": \00"
define i32 @debug_set_prefix(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* %5
%11 = icmp ugt i32 %10, 3
br label %12
12: ; preds = %9, %3
%13 = phi i1 [ false, %3 ], [ %11, %9 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = call i32 @freeipmi_memset(i8* %16, i8 signext 0, i32 %17)
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %43
21: ; preds = %12
%22 = load i8*, i8** %4
%23 = load i8*, i8** %6
%24 = load i32, i32* %5
%25 = call i32 @strncpy(i8* %22, i8* %23, i32 %24)
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = sub i32 %27, 1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %4
%32 = load i32, i32* %5
%33 = sub i32 %32, 2
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %4
%37 = load i32, i32* %5
%38 = sub i32 %37, 3
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 0, i8* %40
%41 = load i8*, i8** %4
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %21, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c": \00"
define i32 @debug_set_prefix(i8* %0, i32 %1, i8* %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ugt i32 %1, 3
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @freeipmi_memset(i8* %0, i8 signext 0, i32 %1)
%10 = icmp eq i8* %2, null
br i1 %10, label %23, label %11
11: ; preds = %3
%12 = tail call i32 @strncpy(i8* %0, i8* %2, i32 %1)
%13 = add i32 %1, -1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
%16 = add i32 %1, -2
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 0, i8* %18
%19 = add i32 %1, -3
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 0, i8* %21
%22 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %11, %3
ret i32 0
}