#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 *);
int /*<<< orphan*/ printf(char *);
char *reverse(char *, char **, size_t *);
int /*<<< orphan*/ strcmp(char *, char *);
int test_reverse() {
  char *string0 = "";
  char *string1 = "abcdefghijklmnopqrstuvwxyz";
  char *string2 = "zyxwvutsrqponmlkjihgfedcba";
  char *tmp = NULL;
  size_t tmp_n = 0;
  char *tmp2 = NULL;
  tmp2 = reverse(NULL, &tmp, &tmp_n);
  if (tmp2 == NULL) {
    printf("ok\n");
  }
  tmp2 = reverse(string0, &tmp, &tmp_n);
  if (!strcmp(string0, tmp2)) {
    printf("ok\n");
  }
  tmp2 = reverse(string1, &tmp, &tmp_n);
  if (!strcmp(string2, tmp2)) {
    printf("ok\n");
  }
  tmp2 = reverse(string2, &tmp, &tmp_n);
  if (!strcmp(string1, tmp2)) {
    printf("ok\n");
  }
  if (tmp != NULL) {
    free(tmp);
    tmp = NULL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeea(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xeb6(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <reverse@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ad <test_reverse+0x6d>
lea    0xe8e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <reverse@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11e4 <test_reverse+0xa4>
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <reverse@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    121b <test_reverse+0xdb>
lea    0xe20(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <reverse@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1252 <test_reverse+0x112>
lea    0xde9(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
je     126e <test_reverse+0x12e>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_reverse>:
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %edi,%edi
call   1030 <reverse@plt>
test   %rax,%rax
jne    1178 <test_reverse+0x38>
lea    0xec3(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb6(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1030 <reverse@plt>
cmpb   $0x0,(%rax)
jne    119f <test_reverse+0x5f>
lea    0xe9c(%rip),%rdi
call   1050 <puts@plt>
lea    0xe5a(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1030 <reverse@plt>
lea    0xe5f(%rip),%rdi
mov    %rax,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11d4 <test_reverse+0x94>
lea    0xe67(%rip),%rdi
call   1050 <puts@plt>
lea    0xe40(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1030 <reverse@plt>
lea    0xe0f(%rip),%rdi
mov    %rax,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1209 <test_reverse+0xc9>
lea    0xe32(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1218 <test_reverse+0xd8>
call   1040 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@.str.2 = [27 x i8] c"zyxwvutsrqponmlkjihgfedcba\00"
@.str.3 = [4 x i8] c"ok\0A\00"
define i32 @test_reverse() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8** %3
store i8* null, i8** %4
store i64 0, i64* %5
store i8* null, i8** %6
%7 = call i8* @reverse(i8* null, i8** %4, i64* %5)
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = load i8*, i8** %1
%14 = call i8* @reverse(i8* %13, i8** %4, i64* %5)
store i8* %14, i8** %6
%15 = load i8*, i8** %1
%16 = load i8*, i8** %6
%17 = call i32 @strcmp(i8* %15, i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %12
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %12
%22 = load i8*, i8** %2
%23 = call i8* @reverse(i8* %22, i8** %4, i64* %5)
store i8* %23, i8** %6
%24 = load i8*, i8** %3
%25 = load i8*, i8** %6
%26 = call i32 @strcmp(i8* %24, i8* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %21
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %21
%31 = load i8*, i8** %3
%32 = call i8* @reverse(i8* %31, i8** %4, i64* %5)
store i8* %32, i8** %6
%33 = load i8*, i8** %2
%34 = load i8*, i8** %6
%35 = call i32 @strcmp(i8* %33, i8* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %30
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %30
%40 = load i8*, i8** %4
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i8*, i8** %4
%44 = call i32 @free(i8* %43)
store i8* null, i8** %4
br label %45
45: ; preds = %42, %39
ret i32 0
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@.str.2 = [27 x i8] c"zyxwvutsrqponmlkjihgfedcba\00"
@str.6 = [3 x i8] c"ok\00"
define i32 @test_reverse() {
%1 = alloca i8*
%2 = alloca i64
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = call i8* @reverse(i8* null, i8** %1, i64* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.6, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i8* @reverse(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %1, i64* %2)
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.6, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = call i8* @reverse(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8** %1, i64* %2)
%17 = call i32 @strcmp(i8* dereferenceable(27) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(1) %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.6, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = call i8* @reverse(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8** %1, i64* %2)
%23 = call i32 @strcmp(i8* dereferenceable(27) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.6, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = load i8*, i8** %1
%29 = icmp eq i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @free(i8* %28)
br label %32
32: ; preds = %30, %27
ret i32 0
}