#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*/ memset(char *, int /*<<< orphan*/, scalar_t__);
char *strdup(char const *);
scalar_t__ strlen(char const *);
char *stripper_dup(const char *str) {
  char *ptr = strdup(str);
  char *inptr = (char *)str;
  int intag = 0;
  char buffer;
  char *p = ptr;
  memset(ptr, 0, strlen(str) + 1);
  while ((buffer = *inptr++) != '\0') {
    if (buffer == '<') {
      intag++;
      continue;
    }
    if (buffer == '>') {
      intag--;
      continue;
    }
    if (intag < 1)
      *(ptr++) = buffer;
  }
  return p;
}


x86 assembly (clang, -O0):
<stripper_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11fc <stripper_dup+0xcc>
movsbl -0x1d(%rbp),%eax
cmp    $0x3c,%eax
jne    11be <stripper_dup+0x8e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1183 <stripper_dup+0x53>
movsbl -0x1d(%rbp),%eax
cmp    $0x3e,%eax
jne    11d9 <stripper_dup+0xa9>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1183 <stripper_dup+0x53>
cmpl   $0x1,-0x1c(%rbp)
jge    11f7 <stripper_dup+0xc7>
mov    -0x1d(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1183 <stripper_dup+0x53>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripper_dup>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <strdup@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14,%rax
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%ecx
test   %cl,%cl
je     1195 <stripper_dup+0x65>
cmp    $0x3e,%cl
je     1181 <stripper_dup+0x51>
cmp    $0x3c,%cl
je     1188 <stripper_dup+0x58>
add    $0x1,%rbx
test   %ebp,%ebp
jg     1160 <stripper_dup+0x30>
mov    %cl,(%rax)
add    $0x1,%rax
jmp    1160 <stripper_dup+0x30>
mov    $0xffffffff,%ecx
jmp    118d <stripper_dup+0x5d>
mov    $0x1,%ecx
add    %ecx,%ebp
add    $0x1,%rbx
jmp    1160 <stripper_dup+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @stripper_dup(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add nsw i64 %3, 1
%5 = tail call i32 @memset(i8* %2, i32 0, i64 %4)
br label %6
6: ; preds = %19, %1
%7 = phi i32 [ 0, %1 ], [ %21, %19 ]
%8 = phi i8* [ %0, %1 ], [ %16, %19 ]
%9 = phi i8* [ %2, %1 ], [ %13, %19 ]
%10 = icmp slt i32 %7, 1
br label %11
11: ; preds = %23, %6
%12 = phi i8* [ %16, %23 ], [ %8, %6 ]
%13 = phi i8* [ %24, %23 ], [ %9, %6 ]
br label %14
14: ; preds = %11, %22
%15 = phi i8* [ %16, %22 ], [ %12, %11 ]
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %15
switch i8 %17, label %22 [
i8 0, label %25
i8 60, label %18
i8 62, label %19
]
18: ; preds = %14
br label %19
19: ; preds = %14, %18
%20 = phi i32 [ 1, %18 ], [ -1, %14 ]
%21 = add nsw i32 %7, %20
br label %6
22: ; preds = %14
br i1 %10, label %23, label %14
23: ; preds = %22
%24 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %17, i8* %13
br label %11
25: ; preds = %14
ret i8* %2
}