#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 */
scalar_t__ strcmp(char const *, char *);
size_t strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, size_t);
int isCharsetUTF8(const char *name) {
  {
    const char *substring = "utf";
    size_t length = strlen(substring);
    if (strncasecmp(name, substring, length) != 0)
      return 0;
    name += length;
    if (*name == '-')
      name += 1;
  }
  return strcmp(name, "8") == 0;
}


x86 assembly (clang, -O0):
<isCharsetUTF8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
je     117b <isCharsetUTF8+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <isCharsetUTF8+0x92>
mov    -0x20(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11a3 <isCharsetUTF8+0x73>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isCharsetUTF8>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1141 <isCharsetUTF8+0x21>
pop    %rbx
ret
lea    0x3(%rbx),%rdi
lea    0x4(%rbx),%rax
cmpb   $0x2d,0x3(%rbx)
cmove  %rax,%rdi
lea    0xeac(%rip),%rsi
call   1030 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"utf\00"
@.str.1 = [2 x i8] c"8\00"
define i32 @isCharsetUTF8(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = load i8*, i8** %4
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %5
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = load i64, i64* %5
%11 = call i64 @strncasecmp(i8* %8, i8* %9, i64 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 0, i32* %2
br label %30
14: ; preds = %1
%15 = load i64, i64* %5
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 %15
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 45
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %3
br label %25
25: ; preds = %22, %14
%26 = load i8*, i8** %3
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
store i32 %29, i32* %2
br label %30
30: ; preds = %25, %13
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [4 x i8] c"utf\00"
@.str.1 = [2 x i8] c"8\00"
define i32 @isCharsetUTF8(i8* %0) {
%2 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 3)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %13
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 3
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 45
%8 = getelementptr inbounds i8, i8* %0, i64 4
%9 = select i1 %7, i8* %8, i8* %5
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %1, %4
%14 = phi i32 [ %12, %4 ], [ 0, %1 ]
ret i32 %14
}