#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 */
char *malloc(int const);
int /*<<< orphan*/ memcpy(char *, char *, int const);
int strlen(char *);
char *joinrev(char *a, char *b) {
  const int alength = strlen(a), blength = strlen(b);
  char *c = malloc(alength + blength + 1);
  if (!c)
    return 0;
  memcpy(c, a, alength);
  memcpy(c + alength, b, blength + 1);
  char temp, *right, *left;
  left = c + alength;
  right = c + alength + blength - 1;
  while (left < right) {
    temp = *right;
    *right-- = *left;
    *left++ = temp;
  }
  return c;
}


x86 assembly (clang, -O0):
<joinrev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
add    -0x20(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1182 <joinrev+0x52>
movq   $0x0,-0x8(%rbp)
jmp    1224 <joinrev+0xf4>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    121c <joinrev+0xec>
mov    -0x38(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x29(%rbp),%cl
mov    -0x40(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x40(%rbp)
mov    %cl,(%rax)
jmp    11d5 <joinrev+0xa5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<joinrev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
lea    (%r15,%r13,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     11cc <joinrev+0x9c>
lea    0x1(%r15),%eax
mov    %eax,0x4(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
movslq %r13d,%r12
lea    (%r14,%r12,1),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    0x4(%rsp),%edx
call   1040 <memcpy@plt>
movslq %r15d,%rax
add    %rbp,%rax
add    $0xffffffffffffffff,%rax
cmp    %rax,%rbp
jae    11cc <joinrev+0x9c>
lea    (%r12,%r14,1),%rcx
add    $0x1,%rcx
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%edx
movzbl -0x1(%rcx),%ebx
mov    %bl,(%rax)
mov    %dl,-0x1(%rcx)
add    $0xffffffffffffffff,%rax
lea    0x1(%rcx),%rdx
cmp    %rax,%rcx
mov    %rdx,%rcx
jb     11b0 <joinrev+0x80>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @joinrev(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %6
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %7
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = add nsw i32 %16, %17
%19 = add nsw i32 %18, 1
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = icmp ne i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %2
store i8* null, i8** %3
br label %65
24: ; preds = %2
%25 = load i8*, i8** %8
%26 = load i8*, i8** %4
%27 = load i32, i32* %6
%28 = call i32 @memcpy(i8* %25, i8* %26, i32 %27)
%29 = load i8*, i8** %8
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8*, i8** %5
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
%36 = call i32 @memcpy(i8* %32, i8* %33, i32 %35)
%37 = load i8*, i8** %8
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8* %40, i8** %11
%41 = load i8*, i8** %8
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = getelementptr inbounds i8, i8* %47, i64 -1
store i8* %48, i8** %10
br label %49
49: ; preds = %53, %24
%50 = load i8*, i8** %11
%51 = load i8*, i8** %10
%52 = icmp ult i8* %50, %51
br i1 %52, label %53, label %63
53: ; preds = %49
%54 = load i8*, i8** %10
%55 = load i8, i8* %54
store i8 %55, i8* %9
%56 = load i8*, i8** %11
%57 = load i8, i8* %56
%58 = load i8*, i8** %10
%59 = getelementptr inbounds i8, i8* %58, i32 -1
store i8* %59, i8** %10
store i8 %57, i8* %58
%60 = load i8, i8* %9
%61 = load i8*, i8** %11
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %11
store i8 %60, i8* %61
br label %49
63: ; preds = %49
%64 = load i8*, i8** %8
store i8* %64, i8** %3
br label %65
65: ; preds = %63, %23
%66 = load i8*, i8** %3
ret i8* %66
}

LLVM IR (-O2):
define i8* @joinrev(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add i32 %4, 1
%6 = add i32 %5, %3
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %26, label %9
9: ; preds = %2
%10 = tail call i32 @memcpy(i8* %7, i8* %0, i32 %3)
%11 = sext i32 %3 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = tail call i32 @memcpy(i8* %12, i8* %1, i32 %5)
%14 = sext i32 %4 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = icmp ult i8* %12, %16
br i1 %17, label %18, label %26
18: ; preds = %9, %18
%19 = phi i8* [ %24, %18 ], [ %16, %9 ]
%20 = phi i8* [ %23, %18 ], [ %12, %9 ]
%21 = load i8, i8* %19
%22 = load i8, i8* %20
store i8 %22, i8* %19
%23 = getelementptr inbounds i8, i8* %20, i64 1
store i8 %21, i8* %20
%24 = getelementptr inbounds i8, i8* %19, i64 -1
%25 = icmp ult i8* %23, %24
br i1 %25, label %18, label %26
26: ; preds = %18, %9, %2
ret i8* %7
}