#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*/ Abort(char *, ...);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
scalar_t__ strtol(char *, char **, int);
scalar_t__ tolower(char);
unsigned short GetPattern(char *pArgStr, char *pBuffer) {
  char number[4];
  char *pEnd;
  char *pStart;
  pStart = pBuffer;
  number[3] = '\0';
  while (*pArgStr != '\0') {
    if (*pArgStr != ':')
      *pBuffer++ = *pArgStr++;
    else {
      if (*(pArgStr + 1) == ':') {
        *pBuffer++ = *pArgStr;
        pArgStr = pArgStr + 2;
      } else {
        if (strlen(++pArgStr) > 2) {
          memcpy(number, pArgStr, 3);
          pArgStr += 3;
          if ((char)tolower(number[0]) == 'x') {
            number[0] = '0';
            *pBuffer++ = (char)strtol(number, &pEnd, 16);
            if (pEnd != number + 3)
              Abort("command error, not a valid hexadecimal number : %s\n",
                    &number[1]);
          } else {
            *pBuffer++ = (char)strtol(number, &pEnd, 10);
            if (pEnd != number + 3)
              Abort("command error, not a valid decimal number : %s\n", number);
          }
        } else
          Abort("command error, a single colon must be followed by three "
                "decimal digits or an 'x' followed by 2 hexadecimal numbers\n");
      }
    }
    if (pBuffer - pStart > 256)
      Abort("command error, length of search or replace buffer must not exceed "
            "%d chars",
            256);
  }
  return pBuffer - pStart;
}


x86 assembly (clang, -O0):
<GetPattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     132f <GetPattern+0x1df>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     11b3 <GetPattern+0x63>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1300 <GetPattern+0x1b0>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3a,%eax
jne    11ec <GetPattern+0x9c>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    12fb <GetPattern+0x1ab>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x8(%rbp)
call   1030 <strlen@plt>
cmp    $0x2,%eax
jle    12e8 <GetPattern+0x198>
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x3,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
movsbl -0x14(%rbp),%edi
call   1060 <tolower@plt>
movsbl %al,%eax
cmp    $0x78,%eax
jne    1292 <GetPattern+0x142>
movb   $0x30,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
lea    -0x14(%rbp),%rcx
add    $0x3,%rcx
cmp    %rcx,%rax
je     128d <GetPattern+0x13d>
lea    -0x14(%rbp),%rsi
add    $0x1,%rsi
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1070 <Abort@plt>
jmp    12e3 <GetPattern+0x193>
lea    -0x14(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
lea    -0x14(%rbp),%rcx
add    $0x3,%rcx
cmp    %rcx,%rax
je     12de <GetPattern+0x18e>
lea    -0x14(%rbp),%rsi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1070 <Abort@plt>
jmp    12e3 <GetPattern+0x193>
jmp    12f6 <GetPattern+0x1a6>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1070 <Abort@plt>
jmp    12fb <GetPattern+0x1ab>
jmp    1300 <GetPattern+0x1b0>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x100,%rax
jle    132a <GetPattern+0x1da>
lea    0xdba(%rip),%rdi
mov    $0x100,%esi
mov    $0x0,%al
call   1070 <Abort@plt>
jmp    116c <GetPattern+0x1c>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
movzwl %ax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetPattern>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
movb   $0x0,0xf(%rsp)
lea    0xc(%rsp),%r15
lea    0xf63(%rip),%r12
mov    %rsi,%rbx
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp),%eax
cmp    $0x3a,%al
je     11a0 <GetPattern+0x50>
test   %al,%al
je     12a6 <GetPattern+0x156>
add    $0x1,%rbp
mov    %al,(%rbx)
add    $0x1,%rbx
jmp    1280 <GetPattern+0x130>
nop
cmpb   $0x3a,0x1(%rbp)
jne    11c0 <GetPattern+0x70>
movb   $0x3a,(%rbx)
add    $0x1,%rbx
add    $0x2,%rbp
jmp    1280 <GetPattern+0x130>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rbp),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jl     122a <GetPattern+0xda>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x3,%edx
call   1050 <memcpy@plt>
add    $0x4,%rbp
movsbl 0xc(%rsp),%edi
call   1060 <tolower@plt>
cmp    $0x78,%al
jne    123d <GetPattern+0xed>
movb   $0x30,0xc(%rsp)
mov    %r15,%rdi
lea    0x10(%rsp),%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
lea    0xf(%rsp),%rax
cmp    %rax,0x10(%rsp)
je     1280 <GetPattern+0x130>
lea    0xddd(%rip),%rdi
lea    0xd(%rsp),%rsi
jmp    126b <GetPattern+0x11b>
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1070 <Abort@plt>
mov    %r13,%rbp
jmp    1280 <GetPattern+0x130>
mov    %r15,%rdi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
lea    0xf(%rsp),%rax
cmp    %rax,0x10(%rsp)
je     1280 <GetPattern+0x130>
lea    0xdcc(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <Abort@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rax
sub    %r14,%rax
cmp    $0x101,%rax
jl     1180 <GetPattern+0x30>
mov    %r12,%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1070 <Abort@plt>
jmp    1180 <GetPattern+0x30>
sub    %r14d,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"command error, not a valid hexadecimal number : %s\0A\00"
@.str.1 = [48 x i8] c"command error, not a valid decimal number : %s\0A\00"
@.str.2 = [116 x i8] c"command error, a single colon must be followed by three decimal digits or an 'x' followed by 2 hexadecimal numbers\0A\00"
@.str.3 = [75 x i8] c"command error, length of search or replace buffer must not exceed %d chars\00"
define zeroext i16 @GetPattern(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [4 x i8]
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
store i8* %8, i8** %7
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 0, i8* %9
br label %10
10: ; preds = %99, %2
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %100
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 58
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
%23 = load i8, i8* %21
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
store i8 %23, i8* %24
br label %90
26: ; preds = %15
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 58
br i1 %31, label %32, label %39
32: ; preds = %26
%33 = load i8*, i8** %3
%34 = load i8, i8* %33
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %4
store i8 %34, i8* %35
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 2
store i8* %38, i8** %3
br label %89
39: ; preds = %26
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %3
%42 = call i32 @strlen(i8* %41)
%43 = icmp sgt i32 %42, 2
br i1 %43, label %44, label %86
44: ; preds = %39
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%46 = load i8*, i8** %3
%47 = call i32 @memcpy(i8* %45, i8* %46, i32 3)
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i64 3
store i8* %49, i8** %3
%50 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%51 = load i8, i8* %50
%52 = call i64 @tolower(i8 signext %51)
%53 = trunc i64 %52 to i8
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 120
br i1 %55, label %56, label %71
56: ; preds = %44
%57 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8 48, i8* %57
%58 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%59 = call i64 @strtol(i8* %58, i8** %6, i32 16)
%60 = trunc i64 %59 to i8
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %4
store i8 %60, i8* %61
%63 = load i8*, i8** %6
%64 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%65 = getelementptr inbounds i8, i8* %64, i64 3
%66 = icmp ne i8* %63, %65
br i1 %66, label %67, label %70
67: ; preds = %56
%68 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
%69 = call i32 (i8*, ...) @Abort(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %67, %56
br label %85
71: ; preds = %44
%72 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%73 = call i64 @strtol(i8* %72, i8** %6, i32 10)
%74 = trunc i64 %73 to i8
%75 = load i8*, i8** %4
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %4
store i8 %74, i8* %75
%77 = load i8*, i8** %6
%78 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%79 = getelementptr inbounds i8, i8* %78, i64 3
%80 = icmp ne i8* %77, %79
br i1 %80, label %81, label %84
81: ; preds = %71
%82 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%83 = call i32 (i8*, ...) @Abort(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %82)
br label %84
84: ; preds = %81, %71
br label %85
85: ; preds = %84, %70
br label %88
86: ; preds = %39
%87 = call i32 (i8*, ...) @Abort(i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.2, i64 0, i64 0))
br label %88
88: ; preds = %86, %85
br label %89
89: ; preds = %88, %32
br label %90
90: ; preds = %89, %20
%91 = load i8*, i8** %4
%92 = load i8*, i8** %7
%93 = ptrtoint i8* %91 to i64
%94 = ptrtoint i8* %92 to i64
%95 = sub i64 %93, %94
%96 = icmp sgt i64 %95, 256
br i1 %96, label %97, label %99
97: ; preds = %90
%98 = call i32 (i8*, ...) @Abort(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.3, i64 0, i64 0), i32 256)
br label %99
99: ; preds = %97, %90
br label %10
100: ; preds = %10
%101 = load i8*, i8** %4
%102 = load i8*, i8** %7
%103 = ptrtoint i8* %101 to i64
%104 = ptrtoint i8* %102 to i64
%105 = sub i64 %103, %104
%106 = trunc i64 %105 to i16
ret i16 %106
}

LLVM IR (-O2):
@.str = [52 x i8] c"command error, not a valid hexadecimal number : %s\0A\00"
@.str.1 = [48 x i8] c"command error, not a valid decimal number : %s\0A\00"
@.str.2 = [116 x i8] c"command error, a single colon must be followed by three decimal digits or an 'x' followed by 2 hexadecimal numbers\0A\00"
@.str.3 = [75 x i8] c"command error, length of search or replace buffer must not exceed %d chars\00"
define zeroext i16 @GetPattern(i8* %0, i8* %1) {
%3 = alloca [4 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
store i8 0, i8* %7
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%9 = ptrtoint i8* %1 to i64
br label %10
10: ; preds = %60, %2
%11 = phi i8* [ %1, %2 ], [ %53, %60 ]
%12 = phi i8* [ %0, %2 ], [ %54, %60 ]
%13 = load i8, i8* %12
switch i8 %13, label %14 [
i8 0, label %61
i8 58, label %17
]
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %13, i8* %11
br label %52
17: ; preds = %10
%18 = getelementptr inbounds i8, i8* %12, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 58
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %11, i64 1
store i8 58, i8* %11
%23 = getelementptr inbounds i8, i8* %12, i64 2
br label %52
24: ; preds = %17
%25 = call i32 @strlen(i8* %18)
%26 = icmp sgt i32 %25, 2
br i1 %26, label %27, label %50
27: ; preds = %24
%28 = call i32 @memcpy(i8* %5, i8* %18, i32 3)
%29 = getelementptr inbounds i8, i8* %12, i64 4
%30 = load i8, i8* %5
%31 = call i64 @tolower(i8 signext %30)
%32 = and i64 %31, 255
%33 = icmp eq i64 %32, 120
br i1 %33, label %34, label %42
34: ; preds = %27
store i8 48, i8* %5
%35 = call i64 @strtol(i8* %5, i8** %4, i32 16)
%36 = trunc i64 %35 to i8
%37 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %36, i8* %11
%38 = load i8*, i8** %4
%39 = icmp eq i8* %38, %7
br i1 %39, label %52, label %40
40: ; preds = %34
%41 = call i32 (i8*, ...) @Abort(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %52
42: ; preds = %27
%43 = call i64 @strtol(i8* %5, i8** %4, i32 10)
%44 = trunc i64 %43 to i8
%45 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %44, i8* %11
%46 = load i8*, i8** %4
%47 = icmp eq i8* %46, %7
br i1 %47, label %52, label %48
48: ; preds = %42
%49 = call i32 (i8*, ...) @Abort(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %52
50: ; preds = %24
%51 = call i32 (i8*, ...) @Abort(i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %21, %40, %34, %48, %42, %50, %14
%53 = phi i8* [ %16, %14 ], [ %22, %21 ], [ %37, %40 ], [ %37, %34 ], [ %45, %48 ], [ %45, %42 ], [ %11, %50 ]
%54 = phi i8* [ %15, %14 ], [ %23, %21 ], [ %29, %40 ], [ %29, %34 ], [ %29, %48 ], [ %29, %42 ], [ %18, %50 ]
%55 = ptrtoint i8* %53 to i64
%56 = sub i64 %55, %9
%57 = icmp sgt i64 %56, 256
br i1 %57, label %58, label %60
58: ; preds = %52
%59 = call i32 (i8*, ...) @Abort(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.3, i64 0, i64 0), i32 256)
br label %60
60: ; preds = %58, %52
br label %10
61: ; preds = %10
%62 = ptrtoint i8* %11 to i64
%63 = sub i64 %62, %9
%64 = trunc i64 %63 to i16
ret i16 %64
}