#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*/ free(char *);
char *json_encode_string(char *);
int /*<<< orphan*/ printf(char *, char *);
void test_string_encode() {
  char *enc_str;
  char str[1024];
  int i;
  for (i = 0x01; i < 0x30; i++)
    str[i - 1] = i;
  str[i - 1] = '\0';
  enc_str = json_encode_string(str);
  printf("encoded string: %s\n", enc_str);
  free(enc_str);
}


x86 assembly (clang, -O0):
<test_string_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x1,-0x414(%rbp)
cmpl   $0x30,-0x414(%rbp)
jge    1180 <test_string_encode+0x50>
mov    -0x414(%rbp),%eax
mov    %al,%cl
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    1145 <test_string_encode+0x15>
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
call   1050 <json_encode_string@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_string_encode>:
push   %rbx
sub    $0x400,%rsp
movaps 0xec1(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeca(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    %rsp,%rdi
call   1050 <json_encode_string@plt>
mov    %rax,%rbx
lea    0xec3(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"encoded string: %s\0A\00"
define void @test_string_encode() {
%1 = alloca i8*
%2 = alloca [1024 x i8]
%3 = alloca i32
store i32 1, i32* %3
br label %4
4: ; preds = %14, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 48
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = load i32, i32* %3
%9 = trunc i32 %8 to i8
%10 = load i32, i32* %3
%11 = sub nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %12
store i8 %9, i8* %13
br label %14
14: ; preds = %7
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %4
17: ; preds = %4
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %20
store i8 0, i8* %21
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%23 = call i8* @json_encode_string(i8* %22)
store i8* %23, i8** %1
%24 = load i8*, i8** %1
%25 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %1
%27 = call i32 @free(i8* %26)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"encoded string: %s\0A\00"
define void @test_string_encode() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = bitcast [1024 x i8]* %1 to <16 x i8>*
store <16 x i8> <i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16>, <16 x i8>* %3
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 16
%5 = bitcast i8* %4 to <16 x i8>*
store <16 x i8> <i8 17, i8 18, i8 19, i8 20, i8 21, i8 22, i8 23, i8 24, i8 25, i8 26, i8 27, i8 28, i8 29, i8 30, i8 31, i8 32>, <16 x i8>* %5
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 32
store i8 33, i8* %6
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 33
store i8 34, i8* %7
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 34
store i8 35, i8* %8
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 35
store i8 36, i8* %9
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 36
store i8 37, i8* %10
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 37
store i8 38, i8* %11
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 38
store i8 39, i8* %12
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 39
store i8 40, i8* %13
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 40
store i8 41, i8* %14
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 41
store i8 42, i8* %15
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 42
store i8 43, i8* %16
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 43
store i8 44, i8* %17
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 44
store i8 45, i8* %18
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 45
store i8 46, i8* %19
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 46
store i8 47, i8* %20
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 47
store i8 0, i8* %21
%22 = call i8* @json_encode_string(i8* %2)
%23 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @free(i8* %22)
ret void
}