#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 wchar_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *, char *, int);
int /*<<< orphan*/ wcscasecmp(int *, char *);
int wcslen(int const *);
int image_is_hdi(const wchar_t *s) {
  int len;
  wchar_t ext[5] = {0, 0, 0, 0, 0};
  char *ws = (char *)s;
  len = wcslen(s);
  if ((len < 4) || (s[0] == L'.'))
    return 0;
  memcpy(ext, ws + ((len - 4) << 1), 8);
  if (!wcscasecmp(ext, L".HDI"))
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<image_is_hdi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jl     1187 <image_is_hdi+0x47>
mov    -0x10(%rbp),%rax
cmpl   $0x2e,(%rax)
jne    1193 <image_is_hdi+0x53>
movl   $0x0,-0x4(%rbp)
jmp    11df <image_is_hdi+0x9f>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    $0x4,%eax
shl    $0x1,%eax
cltq
add    %rax,%rsi
mov    $0x8,%edx
call   1060 <memcpy@plt>
lea    -0x30(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1050 <wcscasecmp@plt>
cmp    $0x0,%eax
jne    11d8 <image_is_hdi+0x98>
movl   $0x1,-0x4(%rbp)
jmp    11df <image_is_hdi+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<image_is_hdi>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
call   1030 <wcslen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x4,%ecx
jl     1192 <image_is_hdi+0x62>
cmpl   $0x2e,(%rbx)
je     1192 <image_is_hdi+0x62>
lea    (%rcx,%rcx,1),%eax
add    $0xfffffff8,%eax
cltq
add    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
lea    0xe7f(%rip),%rsi
mov    %r14,%rdi
call   1040 <wcscasecmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i32] [i32 46, i32 72, i32 68, i32 73, i32 0]
define i32 @image_is_hdi(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [5 x i32]
%6 = alloca i8*
store i32* %0, i32** %3
%7 = bitcast [5 x i32]* %5 to i8*
%8 = load i32*, i32** %3
%9 = bitcast i32* %8 to i8*
store i8* %9, i8** %6
%10 = load i32*, i32** %3
%11 = call i32 @wcslen(i32* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %19, label %14
14: ; preds = %1
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 46
br i1 %18, label %19, label %20
19: ; preds = %14, %1
store i32 0, i32* %2
br label %34
20: ; preds = %14
%21 = getelementptr inbounds [5 x i32], [5 x i32]* %5, i64 0, i64 0
%22 = load i8*, i8** %6
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 4
%25 = shl i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
%28 = call i32 @memcpy(i32* %21, i8* %27, i32 8)
%29 = getelementptr inbounds [5 x i32], [5 x i32]* %5, i64 0, i64 0
%30 = call i32 @wcscasecmp(i32* %29, i8* bitcast ([5 x i32]* @.str to i8*))
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %20
store i32 1, i32* %2
br label %34
33: ; preds = %20
store i32 0, i32* %2
br label %34
34: ; preds = %33, %32, %19
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [5 x i32] [i32 46, i32 72, i32 68, i32 73, i32 0]
define i32 @image_is_hdi(i32* %0) {
%2 = alloca [5 x i32]
%3 = bitcast [5 x i32]* %2 to i8*
%4 = bitcast i32* %0 to i8*
%5 = tail call i32 @wcslen(i32* %0)
%6 = icmp slt i32 %5, 4
br i1 %6, label %20, label %7
7: ; preds = %1
%8 = load i32, i32* %0
%9 = icmp eq i32 %8, 46
br i1 %9, label %20, label %10
10: ; preds = %7
%11 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%12 = shl nuw i32 %5, 1
%13 = add i32 %12, -8
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %4, i64 %14
%16 = call i32 @memcpy(i32* %11, i8* %15, i32 8)
%17 = call i32 @wcscasecmp(i32* %11, i8* bitcast ([5 x i32]* @.str to i8*))
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %10, %1, %7
%21 = phi i32 [ 0, %7 ], [ 0, %1 ], [ %19, %10 ]
ret i32 %21
}