#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 */
scalar_t__ isalpha(char);
scalar_t__ isdigit(char);
scalar_t__ malloc(int);
unsigned int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
char *getRegex(char *match) {
  char *regex = (char *)malloc(strlen(match) * 2);
  for (unsigned i = 0; i < strlen(match); i++) {
    if (isalpha(match[i])) {
      strncat(regex, "\\w", 2);
    } else if (isdigit(match[i])) {
      strncat(regex, "\\d", 2);
    } else {
      strncat(regex, "\\S", 2);
    }
  }
  return regex;
}


x86 assembly (clang, -O0):
<getRegex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jae    122b <getRegex+0xdb>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1070 <isalpha@plt>
cmp    $0x0,%rax
je     11ca <getRegex+0x7a>
mov    -0x10(%rbp),%rdi
lea    0xe45(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncat@plt>
jmp    1218 <getRegex+0xc8>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11fe <getRegex+0xae>
mov    -0x10(%rbp),%rdi
lea    0xe14(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncat@plt>
jmp    1213 <getRegex+0xc3>
mov    -0x10(%rbp),%rdi
lea    0xdfd(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncat@plt>
jmp    1218 <getRegex+0xc8>
jmp    121d <getRegex+0xcd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117a <getRegex+0x2a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRegex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
lea    (%rax,%rax,1),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11e9 <getRegex+0x99>
xor    %ebx,%ebx
lea    0xe7d(%rip),%r12
lea    0xe7c(%rip),%r13
lea    0xe72(%rip),%rbp
jmp    11c0 <getRegex+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    $0x2,%edx
call   1050 <strncat@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jae    11e9 <getRegex+0x99>
movsbl (%r15,%rbx,1),%edi
call   1070 <isalpha@plt>
mov    %r12,%rsi
test   %rax,%rax
jne    11a0 <getRegex+0x50>
movsbl (%r15,%rbx,1),%edi
call   1030 <isdigit@plt>
mov    %r13,%rsi
test   %rax,%rax
je     11a0 <getRegex+0x50>
mov    %rbp,%rsi
jmp    11a0 <getRegex+0x50>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\w\00"
@.str.1 = [3 x i8] c"\\d\00"
@.str.2 = [3 x i8] c"\\S\00"
define i8* @getRegex(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = mul i32 %6, 2
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
store i32 0, i32* %4
br label %10
10: ; preds = %42, %1
%11 = load i32, i32* %4
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = icmp ult i32 %11, %13
br i1 %14, label %15, label %45
15: ; preds = %10
%16 = load i8*, i8** %2
%17 = load i32, i32* %4
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = call i64 @isalpha(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i8*, i8** %3
%25 = call i32 @strncat(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %41
26: ; preds = %15
%27 = load i8*, i8** %2
%28 = load i32, i32* %4
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i64 @isdigit(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = load i8*, i8** %3
%36 = call i32 @strncat(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %40
37: ; preds = %26
%38 = load i8*, i8** %3
%39 = call i32 @strncat(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
br label %40
40: ; preds = %37, %34
br label %41
41: ; preds = %40, %23
br label %42
42: ; preds = %41
%43 = load i32, i32* %4
%44 = add i32 %43, 1
store i32 %44, i32* %4
br label %10
45: ; preds = %10
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\w\00"
@.str.1 = [3 x i8] c"\\d\00"
@.str.2 = [3 x i8] c"\\S\00"
define i8* @getRegex(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %20, %1
ret i8* %5
9: ; preds = %1, %20
%10 = phi i64 [ %23, %20 ], [ 0, %1 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i64 @isalpha(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %9
%16 = load i8, i8* %11
%17 = tail call i64 @isdigit(i8 signext %16)
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
br label %20
20: ; preds = %15, %9
%21 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %9 ], [ %19, %15 ]
%22 = tail call i32 @strncat(i8* %5, i8* %21, i32 2)
%23 = add nuw nsw i64 %10, 1
%24 = tail call i32 @strlen(i8* %0)
%25 = zext i32 %24 to i64
%26 = icmp ult i64 %23, %25
br i1 %26, label %9, label %8
}