#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*/ ENOMEM;
int /*<<< orphan*/ memmove(char *, char *, size_t);
char *realloc(char *, size_t);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ warnx(char *, int /*<<< orphan*/);
char *mknum(char *str, char ch) {
  static char *copy;
  static size_t copy_size;
  char *newcopy;
  size_t len, newlen;
  len = strlen(str) + 2;
  if (len > copy_size) {
    newlen = ((len + 1023) >> 10) << 10;
    if ((newcopy = realloc(copy, newlen)) == NULL) {
      warnx("%s", strerror(ENOMEM));
      return (NULL);
    }
    copy = newcopy;
    copy_size = newlen;
  }
  memmove(copy, str, len - 3);
  copy[len - 3] = 'j';
  copy[len - 2] = ch;
  copy[len - 1] = '\0';
  return (copy);
}


x86 assembly (clang, -O0):
<mknum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x2,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    0x2ed9(%rip),%rax
jbe    11f8 <mknum+0xa8>
mov    -0x28(%rbp),%rax
add    $0x3ff,%rax
shr    $0xa,%rax
shl    $0xa,%rax
mov    %rax,-0x30(%rbp)
mov    0x2eae(%rip),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e2 <mknum+0x92>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xe30(%rip),%rdi
call   1040 <warnx@plt>
movq   $0x0,-0x8(%rbp)
jmp    1256 <mknum+0x106>
mov    -0x20(%rbp),%rax
mov    %rax,0x2e63(%rip)
mov    -0x30(%rbp),%rax
mov    %rax,0x2e60(%rip)
mov    0x2e51(%rip),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    $0x3,%rdx
call   1060 <memmove@plt>
mov    0x2e39(%rip),%rax
mov    -0x28(%rbp),%rcx
sub    $0x3,%rcx
movb   $0x6a,(%rax,%rcx,1)
mov    -0x11(%rbp),%dl
mov    0x2e23(%rip),%rax
mov    -0x28(%rbp),%rcx
sub    $0x2,%rcx
mov    %dl,(%rax,%rcx,1)
mov    0x2e11(%rip),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2dfe(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mknum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
call   1030 <strlen@plt>
movslq %eax,%rbx
add    $0x2,%rbx
cmp    %rbx,0x2ee8(%rip)
jae    11a7 <mknum+0x57>
lea    0x3ff(%rbx),%rbp
and    $0xfffffffffffffc00,%rbp
mov    0x2ec9(%rip),%rdi
mov    %rbp,%rsi
call   1050 <realloc@plt>
test   %rax,%rax
je     11d2 <mknum+0x82>
mov    %rax,%rdi
mov    %rax,0x2eb2(%rip)
mov    %rbp,0x2eb3(%rip)
jmp    11ae <mknum+0x5e>
mov    0x2ea2(%rip),%rdi
lea    -0x3(%rbx),%rdx
mov    %r15,%rsi
call   1060 <memmove@plt>
mov    0x2e8f(%rip),%rax
movb   $0x6a,-0x3(%rax,%rbx,1)
mov    %r14b,-0x2(%rbx,%rax,1)
movb   $0x0,-0x1(%rbx,%rax,1)
jmp    11f0 <mknum+0xa0>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe19(%rip),%rdi
mov    %eax,%esi
call   1040 <warnx@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@mknum.copy = internal global i8* null
@mknum.copy_size = internal global i64 0
@.str = [3 x i8] c"%s\00"
@ENOMEM = global i32 0
define i8* @mknum(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %4
store i8 %1, i8* %5
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 2
%12 = sext i32 %11 to i64
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = load i64, i64* @mknum.copy_size
%15 = icmp ugt i64 %13, %14
br i1 %15, label %16, label %32
16: ; preds = %2
%17 = load i64, i64* %7
%18 = add i64 %17, 1023
%19 = lshr i64 %18, 10
%20 = shl i64 %19, 10
store i64 %20, i64* %8
%21 = load i8*, i8** @mknum.copy
%22 = load i64, i64* %8
%23 = call i8* @realloc(i8* %21, i64 %22)
store i8* %23, i8** %6
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %16
%26 = load i32, i32* @ENOMEM
%27 = call i32 @strerror(i32 %26)
%28 = call i32 @warnx(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %27)
store i8* null, i8** %3
br label %52
29: ; preds = %16
%30 = load i8*, i8** %6
store i8* %30, i8** @mknum.copy
%31 = load i64, i64* %8
store i64 %31, i64* @mknum.copy_size
br label %32
32: ; preds = %29, %2
%33 = load i8*, i8** @mknum.copy
%34 = load i8*, i8** %4
%35 = load i64, i64* %7
%36 = sub i64 %35, 3
%37 = call i32 @memmove(i8* %33, i8* %34, i64 %36)
%38 = load i8*, i8** @mknum.copy
%39 = load i64, i64* %7
%40 = sub i64 %39, 3
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 106, i8* %41
%42 = load i8, i8* %5
%43 = load i8*, i8** @mknum.copy
%44 = load i64, i64* %7
%45 = sub i64 %44, 2
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %42, i8* %46
%47 = load i8*, i8** @mknum.copy
%48 = load i64, i64* %7
%49 = sub i64 %48, 1
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = load i8*, i8** @mknum.copy
store i8* %51, i8** %3
br label %52
52: ; preds = %32, %25
%53 = load i8*, i8** %3
ret i8* %53
}

LLVM IR (-O2):
@mknum.copy = internal unnamed_addr global i8* null
@mknum.copy_size = internal unnamed_addr global i64 0
@.str = [3 x i8] c"%s\00"
@ENOMEM = global i32 0
define i8* @mknum(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 = load i64, i64* @mknum.copy_size
%7 = icmp ult i64 %6, %5
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = load i8*, i8** @mknum.copy
br label %21
10: ; preds = %2
%11 = add nsw i64 %5, 1023
%12 = and i64 %11, -1024
%13 = load i8*, i8** @mknum.copy
%14 = tail call i8* @realloc(i8* %13, i64 %12)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i32, i32* @ENOMEM
%18 = tail call i32 @strerror(i32 %17)
%19 = tail call i32 @warnx(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %31
20: ; preds = %10
store i8* %14, i8** @mknum.copy
store i64 %12, i64* @mknum.copy_size
br label %21
21: ; preds = %8, %20
%22 = phi i8* [ %9, %8 ], [ %14, %20 ]
%23 = add nsw i64 %5, -3
%24 = tail call i32 @memmove(i8* %22, i8* %0, i64 %23)
%25 = load i8*, i8** @mknum.copy
%26 = getelementptr inbounds i8, i8* %25, i64 %23
store i8 106, i8* %26
%27 = add nsw i64 %5, -2
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %1, i8* %28
%29 = add nsw i64 %5, -1
%30 = getelementptr inbounds i8, i8* %25, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %21, %16
%32 = phi i8* [ null, %16 ], [ %25, %21 ]
ret i8* %32
}