#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__ strcasecmp(char const *, char *);
size_t strlen(char const *);
bool path_is_jpeg(const char *path) {
  size_t n = strlen(path);
  if (n >= 4 && 0 == strcasecmp(path + n - 4, ".jpg"))
    return true;
  if (n >= 5 && 0 == strcasecmp(path + n - 5, ".jpeg"))
    return true;
  return false;
}


x86 assembly (clang, -O0):
<path_is_jpeg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x4,-0x18(%rbp)
jb     1176 <path_is_jpeg+0x56>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xea9(%rip),%rsi
call   1030 <strcasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1176 <path_is_jpeg+0x56>
movl   $0x1,-0x4(%rbp)
jmp    11ba <path_is_jpeg+0x9a>
cmpq   $0x5,-0x18(%rbp)
jb     11b3 <path_is_jpeg+0x93>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe71(%rip),%rsi
call   1030 <strcasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11b3 <path_is_jpeg+0x93>
movl   $0x1,-0x4(%rbp)
jmp    11ba <path_is_jpeg+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_is_jpeg>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x4,%rax
jb     1175 <path_is_jpeg+0x55>
mov    %rax,%rbp
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xebc(%rip),%rsi
call   1030 <strcasecmp@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     1178 <path_is_jpeg+0x58>
cmp    $0x5,%rbp
jb     1175 <path_is_jpeg+0x55>
add    %rbp,%rbx
add    $0xfffffffffffffffb,%rbx
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1178 <path_is_jpeg+0x58>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c".jpg\00"
@.str.1 = [6 x i8] c".jpeg\00"
define i32 @path_is_jpeg(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp ugt i64 %2, 3
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 %2
%6 = getelementptr inbounds i8, i8* %5, i64 -4
%7 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = icmp ugt i64 %2, 4
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = getelementptr inbounds i8, i8* %5, i64 -5
%13 = tail call i64 @strcasecmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %1, %11, %9
br label %16
16: ; preds = %11, %4, %15
%17 = phi i32 [ 0, %15 ], [ 1, %4 ], [ 1, %11 ]
ret i32 %17
}