#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 uint64_t;
typedef int uint16_t;

/* Variables and functions */
char *__aosc_encode_fixed_size_16(char *, int, int);
int /*<<< orphan*/ assert(int);
char *strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *__aosc_backpatch_x86_64(char *dst, uint64_t rsp) {
  char encoded[64];
  uint16_t word1, word2, word3, word4;
  rsp += 14 * 4 + 1;
  word1 = rsp >> 48;
  word2 = (rsp >> 32) & 0xFFFF;
  word3 = (rsp >> 16) & 0xFFFF;
  word4 = rsp & 0xFFFF;
  strcpy(dst, __aosc_encode_fixed_size_16(encoded, 0, word1));
  strcat(dst, __aosc_encode_fixed_size_16(encoded, word1, word2));
  strcat(dst, __aosc_encode_fixed_size_16(encoded, word2, word3));
  strcat(dst, __aosc_encode_fixed_size_16(encoded, word3, word4));
  assert(strlen(dst) == 14 * 4);
  return strcat(dst, "\x5c");
}


x86 assembly (clang, -O0):
<__aosc_backpatch_x86_64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x39,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x30,%ecx
sar    %cl,%eax
mov    %eax,-0x54(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
and    $0xffff,%eax
mov    %eax,-0x58(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x10,%eax
and    $0xffff,%eax
mov    %eax,-0x5c(%rbp)
mov    -0xc(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%edx
xor    %esi,%esi
call   1030 <__aosc_encode_fixed_size_16@plt>
mov    -0x80(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x58(%rbp),%edx
call   1030 <__aosc_encode_fixed_size_16@plt>
mov    -0x78(%rbp),%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%esi
mov    -0x5c(%rbp),%edx
call   1030 <__aosc_encode_fixed_size_16@plt>
mov    -0x70(%rbp),%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x60(%rbp),%edx
call   1030 <__aosc_encode_fixed_size_16@plt>
mov    -0x68(%rbp),%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x38,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xdae(%rip),%rsi
call   1070 <strcat@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__aosc_backpatch_x86_64>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0x39,%ebp
movzwl %bp,%r14d
shr    $0x10,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <__aosc_encode_fixed_size_16@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1030 <__aosc_encode_fixed_size_16@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %r15,%rdi
mov    %ebp,%edx
call   1030 <__aosc_encode_fixed_size_16@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <__aosc_encode_fixed_size_16@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %edi,%edi
cmp    $0x38,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movw   $0x5c,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\\\00"
define i8* @__aosc_backpatch_x86_64(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [64 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 57
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = ashr i32 %12, 48
store i32 %13, i32* %6
%14 = load i32, i32* %4
%15 = ashr i32 %14, 32
%16 = and i32 %15, 65535
store i32 %16, i32* %7
%17 = load i32, i32* %4
%18 = ashr i32 %17, 16
%19 = and i32 %18, 65535
store i32 %19, i32* %8
%20 = load i32, i32* %4
%21 = and i32 %20, 65535
store i32 %21, i32* %9
%22 = load i8*, i8** %3
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%24 = load i32, i32* %6
%25 = call i8* @__aosc_encode_fixed_size_16(i8* %23, i32 0, i32 %24)
%26 = call i32 @strcpy(i8* %22, i8* %25)
%27 = load i8*, i8** %3
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call i8* @__aosc_encode_fixed_size_16(i8* %28, i32 %29, i32 %30)
%32 = call i8* @strcat(i8* %27, i8* %31)
%33 = load i8*, i8** %3
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = call i8* @__aosc_encode_fixed_size_16(i8* %34, i32 %35, i32 %36)
%38 = call i8* @strcat(i8* %33, i8* %37)
%39 = load i8*, i8** %3
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%41 = load i32, i32* %8
%42 = load i32, i32* %9
%43 = call i8* @__aosc_encode_fixed_size_16(i8* %40, i32 %41, i32 %42)
%44 = call i8* @strcat(i8* %39, i8* %43)
%45 = load i8*, i8** %3
%46 = call i32 @strlen(i8* %45)
%47 = icmp eq i32 %46, 56
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i8*, i8** %3
%51 = call i8* @strcat(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret i8* %51
}

LLVM IR (-O2):
define i8* @__aosc_backpatch_x86_64(i8* returned %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = add nsw i32 %1, 57
%6 = lshr i32 %5, 16
%7 = and i32 %5, 65535
%8 = call i8* @__aosc_encode_fixed_size_16(i8* %4, i32 0, i32 poison)
%9 = call i32 @strcpy(i8* %0, i8* %8)
%10 = call i8* @__aosc_encode_fixed_size_16(i8* %4, i32 poison, i32 poison)
%11 = call i8* @strcat(i8* dereferenceable(1) %0, i8* dereferenceable(1) %10)
%12 = call i8* @__aosc_encode_fixed_size_16(i8* %4, i32 poison, i32 %6)
%13 = call i8* @strcat(i8* dereferenceable(1) %0, i8* dereferenceable(1) %12)
%14 = call i8* @__aosc_encode_fixed_size_16(i8* %4, i32 %6, i32 %7)
%15 = call i8* @strcat(i8* dereferenceable(1) %0, i8* dereferenceable(1) %14)
%16 = call i32 @strlen(i8* %0)
%17 = icmp eq i32 %16, 56
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %0)
%21 = getelementptr i8, i8* %0, i64 %20
%22 = bitcast i8* %21 to i16*
store i16 92, i16* %22
ret i8* %0
}