#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(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reverse_char_array(char *);
int /*<<< orphan*/ reverse_string(char *, char *);
int strlen(char *);
int main() {
  char *s1 = "hello, world!";
  char s2[] = "foo bar";
  char *s3, *s4;
  char s5[] = "hello, world!";
  char s6[] = "";
  s3 = malloc(strlen(s1) * sizeof(char) + 1);
  s4 = malloc(strlen(s2) * sizeof(char) + 1);
  assert(s3);
  assert(s4);
  printf("Before reversing:\n");
  printf("=================\n");
  printf("s1: %s\n", s1);
  printf("s2: %s\n", s2);
  printf("s5: %s\n", s5);
  printf("s6: %s\n", s6);
  reverse_string(s3, s1);
  reverse_string(s4, s2);
  reverse_char_array(s5);
  reverse_char_array(s6);
  printf("\nAfter reversing:\n");
  printf("=================\n");
  printf("s3: %s\n", s3);
  printf("s4: %s\n", s4);
  printf("s5: %s\n", s5);
  printf("s6: %s\n", s6);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xe7d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe64(%rip),%rax
mov    %rax,-0x36(%rbp)
mov    0xe62(%rip),%eax
mov    %eax,-0x2e(%rbp)
mov    0xe5c(%rip),%ax
mov    %ax,-0x2a(%rbp)
lea    -0x37(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1070 <assert@plt>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x18(%rbp),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x36(%rbp),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x37(%rbp),%rsi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <reverse_string@plt>
mov    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <reverse_string@plt>
lea    -0x36(%rbp),%rdi
call   1090 <reverse_char_array@plt>
lea    -0x37(%rbp),%rdi
call   1090 <reverse_char_array@plt>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x36(%rbp),%rsi
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x37(%rbp),%rsi
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movabs $0x726162206f6f66,%rax
mov    %rax,0x10(%rsp)
movabs $0x21646c726f7720,%rax
mov    %rax,0x1e(%rsp)
movabs $0x77202c6f6c6c6568,%rax
2c 20 77
mov    %rax,0x18(%rsp)
lea    0xe4e(%rip),%r15
movb   $0x0,0xf(%rsp)
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1070 <assert@plt>
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5d(%rip),%rdi
call   1040 <puts@plt>
lea    0xdfd(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf4(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdeb(%rip),%rdi
lea    0x18(%rsp),%r13
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xddd(%rip),%rdi
lea    0xf(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <reverse_string@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <reverse_string@plt>
mov    %r13,%rdi
call   1090 <reverse_char_array@plt>
mov    %rbp,%rdi
call   1090 <reverse_char_array@plt>
lea    0xdcb(%rip),%rdi
call   1040 <puts@plt>
lea    0xdd1(%rip),%rdi
call   1040 <puts@plt>
lea    0xd91(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd88(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd5f(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd56(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"hello, world!\00"
@__const.main.s2 = [8 x i8] c"foo bar\00"
@__const.main.s5 = [14 x i8] c"hello, world!\00"
@.str.1 = [19 x i8] c"Before reversing:\0A\00"
@.str.2 = [19 x i8] c"=================\0A\00"
@.str.3 = [8 x i8] c"s1: %s\0A\00"
@.str.4 = [8 x i8] c"s2: %s\0A\00"
@.str.5 = [8 x i8] c"s5: %s\0A\00"
@.str.6 = [8 x i8] c"s6: %s\0A\00"
@.str.7 = [19 x i8] c"\0AAfter reversing:\0A\00"
@.str.8 = [8 x i8] c"s3: %s\0A\00"
@.str.9 = [8 x i8] c"s4: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [8 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [14 x i8]
%7 = alloca [1 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
%8 = bitcast [8 x i8]* %3 to i8*
%9 = bitcast [14 x i8]* %6 to i8*
%10 = bitcast [1 x i8]* %7 to i8*
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = add i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %4
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 1
%22 = add i64 %21, 1
%23 = trunc i64 %22 to i32
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %5
%25 = load i8*, i8** %4
%26 = call i32 @assert(i8* %25)
%27 = load i8*, i8** %5
%28 = call i32 @assert(i8* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%31 = load i8*, i8** %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %4
%40 = load i8*, i8** %2
%41 = call i32 @reverse_string(i8* %39, i8* %40)
%42 = load i8*, i8** %5
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%44 = call i32 @reverse_string(i8* %42, i8* %43)
%45 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%46 = call i32 @reverse_char_array(i8* %45)
%47 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%48 = call i32 @reverse_char_array(i8* %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%51 = load i8*, i8** %4
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %51)
%53 = load i8*, i8** %5
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %53)
%55 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %55)
%57 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %57)
ret i32 0
}

LLVM IR (-O2):
@__const.main.s5 = [14 x i8] c"hello, world!\00"
@.str.3 = [8 x i8] c"s1: %s\0A\00"
@.str.4 = [8 x i8] c"s2: %s\0A\00"
@.str.5 = [8 x i8] c"s5: %s\0A\00"
@.str.6 = [8 x i8] c"s6: %s\0A\00"
@.str.8 = [8 x i8] c"s3: %s\0A\00"
@.str.9 = [8 x i8] c"s4: %s\0A\00"
@str = [18 x i8] c"Before reversing:\00"
@str.11 = [18 x i8] c"\0AAfter reversing:\00"
@str.12 = [18 x i8] c"=================\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [14 x i8]
%3 = alloca [1 x i8]
%4 = bitcast i64* %1 to i8*
store i64 32195221423877990, i64* %1
%5 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
store i8 0, i8* %6
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__const.main.s5, i64 0, i64 0))
%8 = add i32 %7, 1
%9 = tail call i8* @malloc(i32 %8)
%10 = call i32 @strlen(i8* %4)
%11 = add i32 %10, 1
%12 = call i8* @malloc(i32 %11)
%13 = call i32 @assert(i8* %9)
%14 = call i32 @assert(i8* %12)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__const.main.s5, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i64* %1)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%21 = call i32 @reverse_string(i8* %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__const.main.s5, i64 0, i64 0))
%22 = call i32 @reverse_string(i8* %12, i8* %4)
%23 = call i32 @reverse_char_array(i8* %5)
%24 = call i32 @reverse_char_array(i8* %6)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %9)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %12)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %6)
ret i32 0
}