#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*/ free(char *);
char hextobyte(char const *);
char *malloc(int);
char *parse_pattern(const char *input, size_t *pattern_size) {
  char *pattern = malloc(0x100);
  size_t size = 0;
  while (*input != '\0') {
    if (*(input + 1) == '\0') {
      goto exit_error;
    }
    pattern[size++] = hextobyte(input);
    ++input;
    ++input;
  }
  if (pattern_size != NULL) {
    *pattern_size = size;
  }
  return pattern;
exit_error:
  if (pattern_size != NULL) {
    *pattern_size = 0;
  }
  free(pattern);
  return NULL;
}


x86 assembly (clang, -O0):
<parse_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ba <parse_pattern+0x8a>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    117c <parse_pattern+0x4c>
jmp    11dd <parse_pattern+0xad>
mov    -0x10(%rbp),%rdi
call   1040 <hextobyte@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1156 <parse_pattern+0x26>
cmpq   $0x0,-0x18(%rbp)
je     11d0 <parse_pattern+0xa0>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1204 <parse_pattern+0xd4>
cmpq   $0x0,-0x18(%rbp)
je     11f3 <parse_pattern+0xc3>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pattern>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
cmpb   $0x0,(%r12)
je     118e <parse_pattern+0x5e>
xor    %r13d,%r13d
mov    %r12,%rbx
nopl   0x0(%rax)
cmpb   $0x0,0x1(%r12,%r13,2)
je     119a <parse_pattern+0x6a>
mov    %rbx,%rdi
call   1040 <hextobyte@plt>
lea    0x1(%r13),%rcx
mov    %al,(%r15,%r13,1)
add    $0x2,%rbx
cmpb   $0x0,0x2(%r12,%r13,2)
mov    %rcx,%r13
jne    1160 <parse_pattern+0x30>
test   %r14,%r14
jne    1195 <parse_pattern+0x65>
jmp    11b1 <parse_pattern+0x81>
xor    %ecx,%ecx
test   %r14,%r14
je     11b1 <parse_pattern+0x81>
mov    %rcx,(%r14)
jmp    11b1 <parse_pattern+0x81>
test   %r14,%r14
je     11a6 <parse_pattern+0x76>
movq   $0x0,(%r14)
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @parse_pattern(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
%8 = call i8* @malloc(i32 256)
store i8* %8, i8** %6
store i64 0, i64* %7
br label %9
9: ; preds = %21, %2
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
br label %40
21: ; preds = %14
%22 = load i8*, i8** %4
%23 = call signext i8 @hextobyte(i8* %22)
%24 = load i8*, i8** %6
%25 = load i64, i64* %7
%26 = add i64 %25, 1
store i64 %26, i64* %7
%27 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 %23, i8* %27
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
br label %9
32: ; preds = %9
%33 = load i64*, i64** %5
%34 = icmp ne i64* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i64, i64* %7
%37 = load i64*, i64** %5
store i64 %36, i64* %37
br label %38
38: ; preds = %35, %32
%39 = load i8*, i8** %6
store i8* %39, i8** %3
br label %48
40: ; preds = %20
%41 = load i64*, i64** %5
%42 = icmp ne i64* %41, null
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = load i64*, i64** %5
store i64 0, i64* %44
br label %45
45: ; preds = %43, %40
%46 = load i8*, i8** %6
%47 = call i32 @free(i8* %46)
store i8* null, i8** %3
br label %48
48: ; preds = %45, %38
%49 = load i8*, i8** %3
ret i8* %49
}

LLVM IR (-O2):
define noalias i8* @parse_pattern(i8* %0, i64* writeonly %1) {
%3 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %2, %12
%7 = phi i64 [ %14, %12 ], [ 0, %2 ]
%8 = phi i8* [ %16, %12 ], [ %0, %2 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %6
%13 = tail call signext i8 @hextobyte(i8* %8)
%14 = add i64 %7, 1
%15 = getelementptr inbounds i8, i8* %3, i64 %7
store i8 %13, i8* %15
%16 = getelementptr inbounds i8, i8* %8, i64 2
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %6
19: ; preds = %12, %2
%20 = phi i64 [ 0, %2 ], [ %14, %12 ]
%21 = icmp eq i64* %1, null
br i1 %21, label %28, label %22
22: ; preds = %19
store i64 %20, i64* %1
br label %28
23: ; preds = %6
%24 = icmp eq i64* %1, null
br i1 %24, label %26, label %25
25: ; preds = %23
store i64 0, i64* %1
br label %26
26: ; preds = %25, %23
%27 = tail call i32 @free(i8* %3)
br label %28
28: ; preds = %19, %22, %26
%29 = phi i8* [ null, %26 ], [ %3, %22 ], [ %3, %19 ]
ret i8* %29
}