#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*/ SEEK_SET;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free_aligned(char *, int);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
char *malloc_aligned(int);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int strncmp(char *, char *, int);
int is_photoframe(int f) {
  int res;
  char id[] = "SITRONIX CORP.";
  char *buff;
  buff = malloc_aligned(0x200);
  if (buff == NULL) {
    fprintf(stderr, "aligned_malloc failed :(\n");
    return 0;
  }
  if (lseek(f, 0x0, SEEK_SET) < 0 || read(f, buff, 0x200) < 0) {
    perror(NULL);
    return 0;
  }
  res = strncmp(buff, id, 15);
  free_aligned(buff, 0x200);
  return !res;
}


x86 assembly (clang, -O0):
<is_photoframe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    0xe7e(%rip),%rax
mov    %rax,-0x1b(%rbp)
mov    0xe7c(%rip),%eax
mov    %eax,-0x13(%rbp)
mov    0xe76(%rip),%ax
mov    %ax,-0xf(%rbp)
mov    0xe6e(%rip),%al
mov    %al,-0xd(%rbp)
mov    $0x200,%edi
call   1040 <malloc_aligned@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11dd <is_photoframe+0x6d>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125e <is_photoframe+0xee>
mov    -0x8(%rbp),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
cmp    $0x0,%rax
jl     1215 <is_photoframe+0xa5>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x200,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jge    122a <is_photoframe+0xba>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    125e <is_photoframe+0xee>
mov    -0x28(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
mov    $0xf,%edx
call   1030 <strncmp@plt>
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x200,%esi
call   1080 <free_aligned@plt>
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_photoframe>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
movabs $0x2e50524f432058,%rax
mov    %rax,0x7(%rsp)
movabs $0x58494e4f52544953,%rax
4e 49 58
mov    %rax,(%rsp)
mov    $0x200,%edi
call   1040 <malloc_aligned@plt>
test   %rax,%rax
je     11fe <is_photoframe+0x8e>
mov    %rax,%r14
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
test   %rax,%rax
js     1220 <is_photoframe+0xb0>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1060 <read@plt>
test   %rax,%rax
js     1220 <is_photoframe+0xb0>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0xf,%edx
call   1030 <strncmp@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    $0x200,%esi
call   1080 <free_aligned@plt>
xor    %ebx,%ebx
test   %ebp,%ebp
sete   %bl
jmp    1215 <is_photoframe+0xa5>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1070 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %edi,%edi
call   1090 <perror@plt>
jmp    1215 <is_photoframe+0xa5>

LLVM IR (-O0):
@__const.is_photoframe.id = [15 x i8] c"SITRONIX CORP.\00"
@stderr = global i32 0
@.str = [26 x i8] c"aligned_malloc failed :(\0A\00"
@SEEK_SET = global i32 0
define i32 @is_photoframe(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [15 x i8]
%6 = alloca i8*
store i32 %0, i32* %3
%7 = bitcast [15 x i8]* %5 to i8*
%8 = call i8* @malloc_aligned(i32 512)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %36
14: ; preds = %1
%15 = load i32, i32* %3
%16 = load i32, i32* @SEEK_SET
%17 = call i64 @lseek(i32 %15, i32 0, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = load i32, i32* %3
%21 = load i8*, i8** %6
%22 = call i64 @read(i32 %20, i8* %21, i32 512)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19, %14
%25 = call i32 @perror(i32* null)
store i32 0, i32* %2
br label %36
26: ; preds = %19
%27 = load i8*, i8** %6
%28 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%29 = call i32 @strncmp(i8* %27, i8* %28, i32 15)
store i32 %29, i32* %4
%30 = load i8*, i8** %6
%31 = call i32 @free_aligned(i8* %30, i32 512)
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
%35 = zext i1 %34 to i32
store i32 %35, i32* %2
br label %36
36: ; preds = %26, %24, %11
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@__const.is_photoframe.id = [15 x i8] c"SITRONIX CORP.\00"
@stderr = global i32 0
@.str = [26 x i8] c"aligned_malloc failed :(\0A\00"
@SEEK_SET = global i32 0
define i32 @is_photoframe(i32 %0) {
%2 = alloca [15 x i8]
%3 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @malloc_aligned(i32 512)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %23
9: ; preds = %1
%10 = load i32, i32* @SEEK_SET
%11 = tail call i64 @lseek(i32 %0, i32 0, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = tail call i64 @read(i32 %0, i8* %4, i32 512)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13, %9
%17 = tail call i32 @perror(i32* null)
br label %23
18: ; preds = %13
%19 = call i32 @strncmp(i8* %4, i8* %3, i32 15)
%20 = call i32 @free_aligned(i8* %4, i32 512)
%21 = icmp eq i32 %19, 0
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %18, %16, %6
%24 = phi i32 [ 0, %6 ], [ 0, %16 ], [ %22, %18 ]
ret i32 %24
}