#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*/ isspace(char);
int /*<<< orphan*/ memset(char *, char, size_t);
size_t strlen(char const *);
char *strstr(char *, char const *);
char *arg_extract_tag(char *str, const char *tag) {
  char *p;
restart:
  p = strstr(str, tag);
  if (p) {
    size_t n = strlen(tag);
    if (p != str && !isspace(p[-1])) {
      str = p + 1;
      goto restart;
    }
    if (p[n] == '=')
      n += 1;
    memset(p, ' ', n);
    p += n;
  }
  return p;
}


x86 assembly (clang, -O0):
<arg_extract_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ed <arg_extract_tag+0xad>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11ae <arg_extract_tag+0x6e>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%eax
jne    11ae <arg_extract_tag+0x6e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1150 <arg_extract_tag+0x10>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    11cf <arg_extract_tag+0x8f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x20,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_extract_tag>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <strstr@plt>
test   %rax,%rax
je     11bf <arg_extract_tag+0x7f>
mov    %rax,%r12
xor    %r14d,%r14d
nop
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
cmp    %rbx,%r12
je     119b <arg_extract_tag+0x5b>
movsbl -0x1(%r12),%edi
call   1050 <isspace@plt>
test   %eax,%eax
jne    119b <arg_extract_tag+0x5b>
mov    %r12,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strstr@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1160 <arg_extract_tag+0x20>
jmp    11c2 <arg_extract_tag+0x82>
xor    %r14d,%r14d
cmpb   $0x3d,(%r12,%r13,1)
sete   %r14b
add    %r13,%r14
mov    %r12,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
add    %r12,%r14
jmp    11c2 <arg_extract_tag+0x82>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @arg_extract_tag(i8* %0, i8* nocapture %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %27, label %5
5: ; preds = %2, %23
%6 = phi i8* [ %25, %23 ], [ %3, %2 ]
%7 = phi i8* [ %24, %23 ], [ %0, %2 ]
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = icmp eq i8* %6, %7
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %6, i64 -1
%12 = load i8, i8* %11
%13 = tail call i32 @isspace(i8 signext %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %5, %10
%16 = getelementptr inbounds i8, i8* %6, i64 %8
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 61
%19 = zext i1 %18 to i64
%20 = add i64 %8, %19
%21 = tail call i32 @memset(i8* %6, i8 signext 32, i64 %20)
%22 = getelementptr inbounds i8, i8* %6, i64 %20
br label %27
23: ; preds = %10
%24 = getelementptr inbounds i8, i8* %6, i64 1
%25 = tail call i8* @strstr(i8* dereferenceable(1) %24, i8* dereferenceable(1) %1)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %5
27: ; preds = %23, %2, %15
%28 = phi i8* [ %22, %15 ], [ null, %2 ], [ null, %23 ]
ret i8* %28
}