#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*/ assert_log(int, int, char *, int *);
char *reverse_str(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int test_reverse_str(int verbose) {
  int ok = 1;
  char *tmp = "0123";
  char *exp = "3210";
  char *rev = reverse_str(tmp);
  assert_log(!strcmp(exp, rev), verbose, "reverse not working", &ok);
  return ok;
}


x86 assembly (clang, -O0):
<test_reverse_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xeb7(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xeb1(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <reverse_str@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
lea    0xe81(%rip),%rdx
lea    -0x8(%rbp),%rcx
call   1050 <assert_log@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_reverse_str>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
lea    0xeba(%rip),%rdi
call   1040 <reverse_str@plt>
lea    0xeb3(%rip),%rdi
mov    %rax,%rsi
call   1030 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
lea    0xea1(%rip),%rdx
lea    0xc(%rsp),%rcx
mov    %ebx,%esi
call   1050 <assert_log@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0123\00"
@.str.1 = [5 x i8] c"3210\00"
@.str.2 = [20 x i8] c"reverse not working\00"
define i32 @test_reverse_str(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %2
store i32 1, i32* %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %5
%7 = load i8*, i8** %4
%8 = call i8* @reverse_str(i8* %7)
store i8* %8, i8** %6
%9 = load i8*, i8** %5
%10 = load i8*, i8** %6
%11 = call i32 @strcmp(i8* %9, i8* %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
%14 = zext i1 %13 to i32
%15 = load i32, i32* %2
%16 = call i32 @assert_log(i32 %14, i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %3
ret i32 %17
}

LLVM IR (-O2):
@.str = [5 x i8] c"0123\00"
@.str.1 = [5 x i8] c"3210\00"
@.str.2 = [20 x i8] c"reverse not working\00"
define i32 @test_reverse_str(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%4 = tail call i8* @reverse_str(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strcmp(i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %4)
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert_log(i32 %7, i32 %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
ret i32 %9
}