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

/* Variables and functions */
int /*<<< orphan*/ CopyCStringToPascal(char *, unsigned char *);
int /*<<< orphan*/ DebugStr(unsigned char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void debugstr(const char *message) {
  char ctemp[256];
  unsigned char ptemp[256];
  int len;
  len = strlen(message);
  if (len >= sizeof(ctemp))
    len = sizeof(ctemp) - 1;
  strncpy(ctemp, message, len);
  ctemp[len] = 0;
  CopyCStringToPascal(ctemp, ptemp);
  DebugStr(ptemp);
}


x86 assembly (clang, -O0):
<debugstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x214(%rbp)
movslq -0x214(%rbp),%rax
cmp    $0x100,%rax
jb     117b <debugstr+0x3b>
movl   $0xff,-0x214(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x214(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x214(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1040 <CopyCStringToPascal@plt>
lea    -0x210(%rbp),%rdi
call   1060 <DebugStr@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debugstr>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
call   1050 <strlen@plt>
cmp    $0xff,%eax
mov    $0xff,%ebx
cmovb  %eax,%ebx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%rbx,1)
lea    0x100(%rsp),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <CopyCStringToPascal@plt>
mov    %rbx,%rdi
call   1060 <DebugStr@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @debugstr(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = icmp uge i64 %9, 256
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 255, i32* %5
br label %12
12: ; preds = %11, %1
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = load i8*, i8** %2
%15 = load i32, i32* %5
%16 = call i32 @strncpy(i8* %13, i8* %14, i32 %15)
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%22 = call i32 @CopyCStringToPascal(i8* %20, i8* %21)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = call i32 @DebugStr(i8* %23)
ret void
}

LLVM IR (-O2):
define void @debugstr(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp ult i32 %6, 255
%8 = select i1 %7, i32 %6, i32 255
%9 = call i32 @strncpy(i8* %4, i8* %0, i32 %8)
%10 = zext i32 %8 to i64
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @CopyCStringToPascal(i8* %4, i8* %5)
%13 = call i32 @DebugStr(i8* %5)
ret void
}