#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*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int extract_fromcode(char *from_code, const char *src) {
  char *p = (char *)src;
  char *fmt = "%*[=\" ]%36[^\" ]";
  for (; *p; p++) {
    if (!strncasecmp(p, "charset", 7)) {
      sscanf(p + 7, fmt, from_code);
      return 0;
    }
    if (!strncasecmp(p, "</head>", 7))
      return -1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<extract_fromcode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xec1(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11cf <extract_fromcode+0xaf>
mov    -0x20(%rbp),%rdi
lea    0xeb5(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncasecmp@plt>
cmp    $0x0,%eax
jne    118f <extract_fromcode+0x6f>
mov    -0x20(%rbp),%rdi
add    $0x7,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <sscanf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d6 <extract_fromcode+0xb6>
mov    -0x20(%rbp),%rdi
lea    0xe7e(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11b9 <extract_fromcode+0x99>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <extract_fromcode+0xb6>
jmp    11be <extract_fromcode+0x9e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1143 <extract_fromcode+0x23>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_fromcode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r15d
cmpb   $0x0,(%rsi)
je     119d <extract_fromcode+0x7d>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xed0(%rip),%r12
lea    0xed1(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x7,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
je     1184 <extract_fromcode+0x64>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x7,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
je     119d <extract_fromcode+0x7d>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1150 <extract_fromcode+0x30>
jmp    119d <extract_fromcode+0x7d>
add    $0x7,%rbx
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%*[=\22 ]%36[^\22 ]\00"
@.str.1 = [8 x i8] c"charset\00"
@.str.2 = [8 x i8] c"</head>\00"
define i32 @extract_fromcode(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
store i8* %8, i8** %6
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %7
br label %9
9: ; preds = %29, %2
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %9
%14 = load i8*, i8** %6
%15 = call i32 @strncasecmp(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%16 = icmp ne i32 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %13
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i64 7
%20 = load i8*, i8** %7
%21 = load i8*, i8** %4
%22 = call i32 @sscanf(i8* %19, i8* %20, i8* %21)
store i32 0, i32* %3
br label %33
23: ; preds = %13
%24 = load i8*, i8** %6
%25 = call i32 @strncasecmp(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %23
store i32 -1, i32* %3
br label %33
28: ; preds = %23
br label %29
29: ; preds = %28
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
br label %9
32: ; preds = %9
store i32 -1, i32* %3
br label %33
33: ; preds = %32, %27, %17
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [16 x i8] c"%*[=\22 ]%36[^\22 ]\00"
@.str.1 = [8 x i8] c"charset\00"
@.str.2 = [8 x i8] c"</head>\00"
define i32 @extract_fromcode(i8* %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %19, label %5
5: ; preds = %2, %15
%6 = phi i8* [ %16, %15 ], [ %1, %2 ]
%7 = tail call i32 @strncasecmp(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %6, i64 7
%11 = tail call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %19
12: ; preds = %5
%13 = tail call i32 @strncasecmp(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %6, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %5
19: ; preds = %12, %15, %2, %9
%20 = phi i32 [ 0, %9 ], [ -1, %2 ], [ -1, %15 ], [ -1, %12 ]
ret i32 %20
}