#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*/ memmove(char *, char const *, size_t);
int strlen(char const *);
int /*<<< orphan*/ warnx(char *, char const *);
char *mklong(const char *str, char ch) {
  static char copy[64];
  size_t len;
  len = strlen(str) + 2;
  if (len > sizeof copy) {
    warnx("format %s too complex\n", str);
    len = 4;
  }
  (void)memmove(copy, str, len - 3);
  copy[len - 3] = 'j';
  copy[len - 2] = ch;
  copy[len - 1] = '\0';
  return copy;
}


x86 assembly (clang, -O0):
<mklong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x2,%eax
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x40,-0x18(%rbp)
jbe    1177 <mklong+0x47>
mov    -0x8(%rbp),%rsi
lea    0xe96(%rip),%rdi
call   1040 <warnx@plt>
movq   $0x4,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x3,%rdx
lea    0x2ec6(%rip),%rdi
call   1050 <memmove@plt>
mov    -0x18(%rbp),%rcx
sub    $0x3,%rcx
lea    0x2eb2(%rip),%rax
movb   $0x6a,(%rax,%rcx,1)
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rcx
sub    $0x2,%rcx
lea    0x2e9c(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
lea    0x2e8a(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e7f(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mklong>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
call   1030 <strlen@plt>
add    $0x2,%eax
cmp    $0x41,%eax
jb     1160 <mklong+0x30>
lea    0xeaf(%rip),%rdi
mov    %r15,%rsi
call   1040 <warnx@plt>
mov    $0x4,%ebx
jmp    1163 <mklong+0x33>
movslq %eax,%rbx
lea    -0x3(%rbx),%rdx
lea    0x2ee2(%rip),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <memmove@plt>
movb   $0x6a,-0x3(%rbx,%rbp,1)
mov    %r14b,-0x2(%rbx,%rbp,1)
movb   $0x0,-0x1(%rbx,%rbp,1)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@mklong.copy = internal global [64 x i8] zeroinitializer
@.str = [23 x i8] c"format %s too complex\0A\00"
define i8* @mklong(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i64
store i8* %0, i8** %3
store i8 %1, i8* %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 2
%9 = sext i32 %8 to i64
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = icmp ugt i64 %10, 64
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @warnx(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %13)
store i64 4, i64* %5
br label %15
15: ; preds = %12, %2
%16 = load i8*, i8** %3
%17 = load i64, i64* %5
%18 = sub i64 %17, 3
%19 = call i32 @memmove(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 0), i8* %16, i64 %18)
%20 = load i64, i64* %5
%21 = sub i64 %20, 3
%22 = getelementptr inbounds [64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 %21
store i8 106, i8* %22
%23 = load i8, i8* %4
%24 = load i64, i64* %5
%25 = sub i64 %24, 2
%26 = getelementptr inbounds [64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 %25
store i8 %23, i8* %26
%27 = load i64, i64* %5
%28 = sub i64 %27, 1
%29 = getelementptr inbounds [64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 %28
store i8 0, i8* %29
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 0)
}

LLVM IR (-O2):
@mklong.copy = internal global [64 x i8] zeroinitializer
@.str = [23 x i8] c"format %s too complex\0A\00"
define i8* @mklong(i8* %0, i8 signext %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 2
%5 = sext i32 %4 to i64
%6 = icmp ugt i32 %4, 64
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @warnx(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %2
%10 = phi i64 [ 4, %7 ], [ %5, %2 ]
%11 = add nsw i64 %10, -3
%12 = tail call i32 @memmove(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 0), i8* %0, i64 %11)
%13 = getelementptr inbounds [64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 %11
store i8 106, i8* %13
%14 = add nsw i64 %10, -2
%15 = getelementptr inbounds [64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 %14
store i8 %1, i8* %15
%16 = add nsw i64 %10, -1
%17 = getelementptr inbounds [64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 %16
store i8 0, i8* %17
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 0)
}