#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 */
typedef int /*<<< orphan*/ u_int32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
char *strdup(int /*<<< orphan*/);
char *strpbrk(char *, char *);
int /*<<< orphan*/ u8_convert_to_str(int /*<<< orphan*/ const *);
int script_tag_get_value(const u_int32_t *u8_str, int *tag_hex_value) {
  char *str = strdup(u8_convert_to_str(u8_str));
  char *first_quote_pos;
  if (NULL == (first_quote_pos = strpbrk(str, "\""))) {
    free(str);
    fprintf(stderr,
            "script_tag_get_value() failed - cannot split string!"
            " - %s:%d\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/msoula/romhacking/refs/heads/master/"
            "hacks/knt/src/utils/tags.c",
            96);
    return -1;
  }
  sscanf(&first_quote_pos[1], "0x%02X", tag_hex_value);
  free(str);
  return 0;
}


x86 assembly (clang, -O0):
<script_tag_get_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <u8_convert_to_str@plt>
mov    %eax,%edi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1060 <strpbrk@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11dc <script_tag_get_value+0x7c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
lea    0xe7a(%rip),%rdx
mov    $0x60,%ecx
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <script_tag_get_value+0xa4>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rdx
lea    0xeea(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<script_tag_get_value>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1070 <u8_convert_to_str@plt>
mov    %eax,%edi
call   1080 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x22,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11aa <script_tag_get_value+0x4a>
add    $0x1,%rax
lea    0xf44(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1060 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11d8 <script_tag_get_value+0x78>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
lea    0xe75(%rip),%rdx
mov    $0x60,%ecx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\22\00"
@stderr = global i32 0
@.str.1 = [62 x i8] c"script_tag_get_value() failed - cannot split string! - %s:%d\0A\00"
@.str.2 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/msoula/romhacking/refs/heads/master/hacks/knt/src/utils/tags.c\00"
@.str.3 = [7 x i8] c"0x%02X\00"
define i32 @script_tag_get_value(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %4
%9 = call i32 @u8_convert_to_str(i32* %8)
%10 = call i8* @strdup(i32 %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = call i8* @strpbrk(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %7
%13 = icmp eq i8* null, %12
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i32 @free(i8* %15)
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.2, i64 0, i64 0), i32 96)
store i32 -1, i32* %3
br label %26
19: ; preds = %2
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i32*, i32** %5
%23 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %22)
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
store i32 0, i32* %3
br label %26
26: ; preds = %19, %14
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [62 x i8] c"script_tag_get_value() failed - cannot split string! - %s:%d\0A\00"
@.str.2 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/msoula/romhacking/refs/heads/master/hacks/knt/src/utils/tags.c\00"
@.str.3 = [7 x i8] c"0x%02X\00"
define i32 @script_tag_get_value(i32* %0, i32* %1) {
%3 = tail call i32 @u8_convert_to_str(i32* %0)
%4 = tail call i8* @strdup(i32 %3)
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i32 34)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 @free(i8* %4)
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.2, i64 0, i64 0), i32 96)
br label %15
11: ; preds = %2
%12 = getelementptr inbounds i8, i8* %5, i64 1
%13 = tail call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%14 = tail call i32 @free(i8* %4)
br label %15
15: ; preds = %11, %7
%16 = phi i32 [ -1, %7 ], [ 0, %11 ]
ret i32 %16
}