#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, int 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    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x2,%eax
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x40,-0x18(%rbp)
jbe    1174 <mklong+0x44>
mov    -0x8(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1040 <warnx@plt>
movq   $0x4,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x3,%rdx
lea    0x2ec9(%rip),%rdi
call   1050 <memmove@plt>
mov    -0x18(%rbp),%rcx
sub    $0x3,%rcx
lea    0x2eb5(%rip),%rax
movb   $0x6a,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rcx
sub    $0x2,%rcx
lea    0x2e9d(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
lea    0x2e8b(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e80(%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, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %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 i32, i32* %4
%24 = trunc i32 %23 to i8
%25 = load i64, i64* %5
%26 = sub i64 %25, 2
%27 = getelementptr inbounds [64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 %26
store i8 %24, i8* %27
%28 = load i64, i64* %5
%29 = sub i64 %28, 1
%30 = getelementptr inbounds [64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 %29
store i8 0, i8* %30
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, i32 %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 = trunc i32 %1 to i8
%15 = add nsw i64 %10, -2
%16 = getelementptr inbounds [64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 %15
store i8 %14, i8* %16
%17 = add nsw i64 %10, -1
%18 = getelementptr inbounds [64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 %17
store i8 0, i8* %18
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @mklong.copy, i64 0, i64 0)
}