#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*/ strcpy(char *, char *);
int strlen(char const *);
char *strstr(char *, char const *);
int strtoul(char *, char **, int);
int remove_tag(char *line, const char *tag) {
  char *pos = strstr(line, tag);
  if (pos == NULL)
    return 0;
  char *end;
  int num = strtoul(pos + strlen(tag), &end, 10);
  strcpy(pos, end);
  return num;
}


x86 assembly (clang, -O0):
<remove_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1178 <remove_tag+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <remove_tag+0x76>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_tag>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbp
call   1060 <strstr@plt>
test   %rax,%rax
je     117e <remove_tag+0x3e>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,%ebp
mov    (%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    1180 <remove_tag+0x40>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @remove_tag(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @strstr(i8* %9, i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %26
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = call i32 @strtoul(i8* %20, i8** %7, i32 10)
store i32 %21, i32* %8
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i32, i32* %8
store i32 %25, i32* %3
br label %26
26: ; preds = %15, %14
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @remove_tag(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = bitcast i8** %3 to i8*
%8 = tail call i32 @strlen(i8* %1)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %4, i64 %9
%11 = call i32 @strtoul(i8* %10, i8** %3, i32 10)
%12 = load i8*, i8** %3
%13 = tail call i32 @strcpy(i8* %4, i8* %12)
br label %14
14: ; preds = %2, %6
%15 = phi i32 [ %11, %6 ], [ 0, %2 ]
ret i32 %15
}