#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int strlen(char *);
char *fitwidth(char *str, int decr) {
  static char buf[65 + 1];
  int len = strlen(str);
  int maxlen = sizeof(buf) - 1 - decr;
  memset(buf, ' ', maxlen);
  buf[maxlen] = 0;
  if (str && sizeof(buf) - decr >= 1) {
    if (len > maxlen)
      len = maxlen;
    memcpy(buf, str, len);
  }
  return (buf);
}


x86 assembly (clang, -O0):
<fitwidth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
movslq -0xc(%rbp),%rcx
mov    $0x41,%eax
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
lea    0x2eec(%rip),%rdi
mov    $0x20,%esi
call   1040 <memset@plt>
movslq -0x14(%rbp),%rcx
lea    0x2ed7(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x8(%rbp)
je     11c3 <fitwidth+0x93>
movslq -0xc(%rbp),%rcx
mov    $0x42,%eax
sub    %rcx,%rax
cmp    $0x1,%rax
jb     11c3 <fitwidth+0x93>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11b0 <fitwidth+0x80>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0x2e92(%rip),%rdi
call   1050 <memcpy@plt>
lea    0x2e86(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fitwidth>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    $0x41,%ebp
sub    %r15d,%ebp
lea    0x2efb(%rip),%r12
mov    %r12,%rdi
mov    $0x20,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
movslq %ebp,%rax
movb   $0x0,(%rax,%r12,1)
test   %rbx,%rbx
je     1190 <fitwidth+0x60>
cmp    $0x42,%r15d
je     1190 <fitwidth+0x60>
cmp    %ebp,%r14d
cmovg  %ebp,%r14d
lea    0x2ecb(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <memcpy@plt>
lea    0x2eb9(%rip),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@fitwidth.buf = internal global [66 x i8] zeroinitializer
define i8* @fitwidth(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = sub i64 65, %10
%12 = trunc i64 %11 to i32
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = call i32 @memset(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @fitwidth.buf, i64 0, i64 0), i8 signext 32, i32 %13)
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [66 x i8], [66 x i8]* @fitwidth.buf, i64 0, i64 %16
store i8 0, i8* %17
%18 = load i8*, i8** %3
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %35
20: ; preds = %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = sub i64 66, %22
%24 = icmp uge i64 %23, 1
br i1 %24, label %25, label %35
25: ; preds = %20
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load i32, i32* %6
store i32 %30, i32* %5
br label %31
31: ; preds = %29, %25
%32 = load i8*, i8** %3
%33 = load i32, i32* %5
%34 = call i32 @memcpy(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @fitwidth.buf, i64 0, i64 0), i8* %32, i32 %33)
br label %35
35: ; preds = %31, %20, %2
ret i8* getelementptr inbounds ([66 x i8], [66 x i8]* @fitwidth.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@fitwidth.buf = internal global [66 x i8] zeroinitializer
define i8* @fitwidth(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = sub i32 65, %1
%5 = tail call i32 @memset(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @fitwidth.buf, i64 0, i64 0), i8 signext 32, i32 %4)
%6 = sext i32 %4 to i64
%7 = getelementptr inbounds [66 x i8], [66 x i8]* @fitwidth.buf, i64 0, i64 %6
store i8 0, i8* %7
%8 = icmp eq i8* %0, null
%9 = icmp eq i32 %1, 66
%10 = or i1 %8, %9
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = icmp sgt i32 %3, %4
%13 = select i1 %12, i32 %4, i32 %3
%14 = tail call i32 @memcpy(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @fitwidth.buf, i64 0, i64 0), i8* %0, i32 %13)
br label %15
15: ; preds = %11, %2
ret i8* getelementptr inbounds ([66 x i8], [66 x i8]* @fitwidth.buf, i64 0, i64 0)
}