#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*/ FILE;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ memcmp(char *, char *, int);
scalar_t__ strncmp(char *, char *, int);
int IMG_isGIF(char *filename) {
  int is_GIF;
  char magic[6];
  FILE *infile = fopen(filename, "rb");
  is_GIF = 0;
  if (fgets(magic, 7, infile)) {
    if ((strncmp(magic, "GIF", 3) == 0) &&
        ((memcmp(magic + 3, "87a", 3) == 0) ||
         (memcmp(magic + 3, "89a", 3) == 0))) {
      is_GIF = 1;
    }
  }
  return (is_GIF);
}


x86 assembly (clang, -O0):
<IMG_isGIF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x12(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x7,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f4 <IMG_isGIF+0xb4>
lea    -0x12(%rbp),%rdi
lea    0xe75(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ef <IMG_isGIF+0xaf>
lea    -0x12(%rbp),%rdi
add    $0x3,%rdi
lea    0xe56(%rip),%rsi
mov    $0x3,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11e8 <IMG_isGIF+0xa8>
lea    -0x12(%rbp),%rdi
add    $0x3,%rdi
lea    0xe37(%rip),%rsi
mov    $0x3,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11ef <IMG_isGIF+0xaf>
movl   $0x1,-0xc(%rbp)
jmp    11f4 <IMG_isGIF+0xb4>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IMG_isGIF>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
lea    0x2(%rsp),%rdi
mov    $0x7,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11c0 <IMG_isGIF+0x80>
lea    0xe93(%rip),%rsi
lea    0x2(%rsp),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11c0 <IMG_isGIF+0x80>
lea    0x5(%rsp),%r14
lea    0xe77(%rip),%rsi
mov    %r14,%rdi
mov    $0x3,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     11bb <IMG_isGIF+0x7b>
lea    0xe62(%rip),%rsi
mov    %r14,%rdi
mov    $0x3,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    11c0 <IMG_isGIF+0x80>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [4 x i8] c"GIF\00"
@.str.2 = [4 x i8] c"87a\00"
@.str.3 = [4 x i8] c"89a\00"
define i32 @IMG_isGIF(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [6 x i8]
%5 = alloca i32*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
store i32 0, i32* %3
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%9 = load i32*, i32** %5
%10 = call i64 @fgets(i8* %8, i32 7, i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %1
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%14 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds i8, i8* %17, i64 3
%19 = call i64 @memcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 3
%24 = call i64 @memcmp(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21, %16
store i32 1, i32* %3
br label %27
27: ; preds = %26, %21, %12
br label %28
28: ; preds = %27, %1
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [4 x i8] c"GIF\00"
@.str.2 = [4 x i8] c"87a\00"
@.str.3 = [4 x i8] c"89a\00"
define i32 @IMG_isGIF(i8* nocapture %0) {
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = call i64 @fgets(i8* %3, i32 7, i32* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %1
%8 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 3
%12 = call i64 @memcmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = call i64 @memcmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %10
br label %18
18: ; preds = %7, %14, %17, %1
%19 = phi i32 [ 1, %17 ], [ 0, %14 ], [ 0, %7 ], [ 0, %1 ]
ret i32 %19
}