#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*/ addnstr(char const *, int const);
scalar_t__ strlen(char const *);
void text_in_a_box(const char *istr) {
  const int len = (int)strlen(istr);
  addnstr(istr, 1);
  if (len > 1) {
    if (len > 2)
      addnstr(istr + 1, len - 2);
    addnstr(istr + len - 1, 1);
  }
}


x86 assembly (clang, -O0):
<text_in_a_box>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <addnstr@plt>
cmpl   $0x1,-0xc(%rbp)
jle    1186 <text_in_a_box+0x66>
cmpl   $0x2,-0xc(%rbp)
jle    116d <text_in_a_box+0x4d>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0xc(%rbp),%esi
sub    $0x2,%esi
call   1040 <addnstr@plt>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
add    $0xffffffffffffffff,%rdi
mov    $0x1,%esi
call   1040 <addnstr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_in_a_box>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <addnstr@plt>
cmp    $0x2,%r14d
jl     116d <text_in_a_box+0x4d>
je     1151 <text_in_a_box+0x31>
lea    0x1(%rbx),%rdi
lea    -0x2(%r14),%esi
call   1040 <addnstr@plt>
movslq %r14d,%rax
lea    (%rbx,%rax,1),%rdi
add    $0xffffffffffffffff,%rdi
mov    $0x1,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <addnstr@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @text_in_a_box(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = tail call i32 @addnstr(i8* %0, i32 1)
%5 = icmp sgt i32 %3, 1
br i1 %5, label %6, label %18
6: ; preds = %1
%7 = icmp eq i32 %3, 2
br i1 %7, label %12, label %8
8: ; preds = %6
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = add nsw i32 %3, -2
%11 = tail call i32 @addnstr(i8* %9, i32 %10)
br label %12
12: ; preds = %8, %6
%13 = shl i64 %2, 32
%14 = ashr exact i64 %13, 32
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = tail call i32 @addnstr(i8* %16, i32 1)
br label %18
18: ; preds = %12, %1
ret void
}