#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*/ decode(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
char *strchr(char *, char);
int strlen(char *);
char *strstr(char *, char *);
char *getTag(const char *tag, char *input, char *output, int outSize) {
  char exactTag[255];
  char *foundT;
  char *lastCHR;
  int tagLength;
  if ((tag == NULL) || (input == NULL) || (output == NULL)) {
    return NULL;
  }
  sprintf(exactTag, " %s%%3A", tag);
  if ((foundT = strstr(input, exactTag)) == NULL) {
    return NULL;
  }
  foundT = strstr(foundT, "%3A") + (3 * sizeof(char));
  if ((lastCHR = strchr(foundT, ' ')) != NULL) {
    tagLength = lastCHR - foundT;
  } else {
    tagLength = strlen(foundT);
  }
  if (tagLength < outSize) {
    decode(foundT, output);
  }
  return output;
}


x86 assembly (clang, -O0):
<getTag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118b <getTag+0x3b>
cmpq   $0x0,-0x18(%rbp)
je     118b <getTag+0x3b>
cmpq   $0x0,-0x20(%rbp)
jne    1198 <getTag+0x48>
movq   $0x0,-0x8(%rbp)
jmp    1272 <getTag+0x122>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x138(%rbp)
cmp    $0x0,%rax
jne    11dd <getTag+0x8d>
movq   $0x0,-0x8(%rbp)
jmp    1272 <getTag+0x122>
mov    -0x138(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1070 <strstr@plt>
add    $0x3,%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x140(%rbp)
cmp    $0x0,%rax
je     1239 <getTag+0xe9>
mov    -0x140(%rbp),%rax
mov    -0x138(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x144(%rbp)
jmp    124b <getTag+0xfb>
mov    -0x138(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x144(%rbp)
mov    -0x144(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    126a <getTag+0x11a>
mov    -0x138(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <decode@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTag>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
xor    %eax,%eax
test   %rdi,%rdi
je     11dd <getTag+0x8d>
mov    %rsi,%rbp
test   %rsi,%rsi
je     11dd <getTag+0x8d>
mov    %rdx,%r15
test   %rdx,%rdx
je     11dd <getTag+0x8d>
mov    %ecx,%r14d
mov    %rdi,%rdx
lea    0xe7f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11db <getTag+0x8b>
lea    0xe61(%rip),%rsi
mov    %rax,%rdi
call   1070 <strstr@plt>
mov    %rax,%rbp
add    $0x3,%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11eb <getTag+0x9b>
sub    %ebp,%eax
cmp    %r14d,%eax
jge    11d6 <getTag+0x86>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <decode@plt>
mov    %r15,%rax
jmp    11dd <getTag+0x8d>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
call   1030 <strlen@plt>
cmp    %r14d,%eax
jl     11cb <getTag+0x7b>
jmp    11d6 <getTag+0x86>

LLVM IR (-O0):
@.str = [8 x i8] c" %s%%3A\00"
@.str.1 = [4 x i8] c"%3A\00"
define i8* @getTag(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [255 x i8]
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %4
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %19, %16, %4
store i8* null, i8** %5
br label %59
23: ; preds = %19
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%25 = load i8*, i8** %6
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %7
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%29 = call i8* @strstr(i8* %27, i8* %28)
store i8* %29, i8** %11
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %23
store i8* null, i8** %5
br label %59
32: ; preds = %23
%33 = load i8*, i8** %11
%34 = call i8* @strstr(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%35 = getelementptr inbounds i8, i8* %34, i64 3
store i8* %35, i8** %11
%36 = load i8*, i8** %11
%37 = call i8* @strchr(i8* %36, i8 signext 32)
store i8* %37, i8** %12
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %46
39: ; preds = %32
%40 = load i8*, i8** %12
%41 = load i8*, i8** %11
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = trunc i64 %44 to i32
store i32 %45, i32* %13
br label %49
46: ; preds = %32
%47 = load i8*, i8** %11
%48 = call i32 @strlen(i8* %47)
store i32 %48, i32* %13
br label %49
49: ; preds = %46, %39
%50 = load i32, i32* %13
%51 = load i32, i32* %9
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i8*, i8** %11
%55 = load i8*, i8** %8
%56 = call i32 @decode(i8* %54, i8* %55)
br label %57
57: ; preds = %53, %49
%58 = load i8*, i8** %8
store i8* %58, i8** %5
br label %59
59: ; preds = %57, %31, %22
%60 = load i8*, i8** %5
ret i8* %60
}

LLVM IR (-O2):
@.str = [8 x i8] c" %s%%3A\00"
@.str.1 = [4 x i8] c"%3A\00"
define i8* @getTag(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [255 x i8]
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %0, null
%8 = icmp eq i8* %1, null
%9 = or i1 %7, %8
%10 = icmp eq i8* %2, null
%11 = or i1 %9, %10
br i1 %11, label %33, label %12
12: ; preds = %4
%13 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = call i8* @strstr(i8* dereferenceable(1) %1, i8* %6)
%15 = icmp eq i8* %14, null
br i1 %15, label %33, label %16
16: ; preds = %12
%17 = tail call i8* @strstr(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds i8, i8* %17, i64 3
%19 = tail call i8* @strchr(i8* %18, i8 signext 32)
%20 = icmp eq i8* %19, null
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = ptrtoint i8* %19 to i64
%23 = ptrtoint i8* %18 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
br label %28
26: ; preds = %16
%27 = tail call i32 @strlen(i8* %18)
br label %28
28: ; preds = %26, %21
%29 = phi i32 [ %25, %21 ], [ %27, %26 ]
%30 = icmp slt i32 %29, %3
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i32 @decode(i8* %18, i8* %2)
br label %33
33: ; preds = %28, %31, %12, %4
%34 = phi i8* [ null, %4 ], [ null, %12 ], [ %2, %31 ], [ %2, %28 ]
ret i8* %34
}