#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*/ bzero(char *, int);
int /*<<< orphan*/ revcomp(char const);
int strlen(char const *);
char toupper(int /*<<< orphan*/);
const char *reverse_pattern(const char *pattern, char *result) {
  int len;
  int i;
  len = strlen(pattern);
  bzero(result, len + 1);
  for (i = 0; i < len; i++)
    result[i] = toupper(revcomp(pattern[len - i - 1]));
  return result;
}


x86 assembly (clang, -O0):
<reverse_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1050 <bzero@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b9 <reverse_pattern+0x79>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <revcomp@plt>
mov    %eax,%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1172 <reverse_pattern+0x32>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_pattern>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%esi
mov    %r15,%rdi
call   1050 <bzero@plt>
test   %ebx,%ebx
jle    1194 <reverse_pattern+0x54>
mov    %ebx,%r12d
add    $0xffffffff,%ebx
xor    %r13d,%r13d
xchg   %ax,%ax
movslq %ebx,%rbx
movsbl (%r14,%rbx,1),%edi
call   1060 <revcomp@plt>
mov    %eax,%edi
call   1030 <toupper@plt>
mov    %al,(%r15,%r13,1)
add    $0x1,%r13
add    $0xffffffff,%ebx
cmp    %r13,%r12
jne    1170 <reverse_pattern+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @reverse_pattern(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
%12 = call i32 @bzero(i8* %9, i32 %11)
store i32 0, i32* %6
br label %13
13: ; preds = %32, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %35
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = sub nsw i32 %19, %20
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %18, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @revcomp(i8 signext %25)
%27 = call signext i8 @toupper(i32 %26)
%28 = load i8*, i8** %4
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %17
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %13
35: ; preds = %13
%36 = load i8*, i8** %4
ret i8* %36
}

LLVM IR (-O2):
define i8* @reverse_pattern(i8* %0, i8* returned writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = tail call i32 @bzero(i8* %1, i32 %4)
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %22
7: ; preds = %2
%8 = zext i32 %3 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %20, %9 ]
%11 = trunc i64 %10 to i32
%12 = xor i32 %11, -1
%13 = add i32 %3, %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = tail call i32 @revcomp(i8 signext %16)
%18 = tail call signext i8 @toupper(i32 %17)
%19 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 %18, i8* %19
%20 = add nuw nsw i64 %10, 1
%21 = icmp eq i64 %20, %8
br i1 %21, label %22, label %9
22: ; preds = %9, %2
ret i8* %1
}