#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 id3_lseek_syncword_r(int, unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ xfree(unsigned char *);
scalar_t__ xmallocd(int, char *);
int id3_lseek_syncword(int fd) {
  unsigned char *data =
      (unsigned char *)xmallocd(4096, "id3_lseek_syncword:data");
  int ret;
  lseek(fd, SEEK_SET, 0);
  if (read(fd, data, 4096) < 1) {
    xfree(data);
    return 0;
  }
  ret = id3_lseek_syncword_r(fd, data, 0);
  xfree(data);
  return ret;
}


x86 assembly (clang, -O0):
<id3_lseek_syncword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x1000,%edi
lea    0xe99(%rip),%rsi
call   1070 <xmallocd@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jge    11b2 <id3_lseek_syncword+0x62>
mov    -0x10(%rbp),%rdi
call   1030 <xfree@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <id3_lseek_syncword+0x82>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1060 <id3_lseek_syncword_r@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <xfree@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id3_lseek_syncword>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
lea    0xea3(%rip),%rsi
mov    $0x1000,%edi
call   1070 <xmallocd@plt>
mov    %rax,%rbx
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11a1 <id3_lseek_syncword+0x51>
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <id3_lseek_syncword_r@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <xfree@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"id3_lseek_syncword:data\00"
@SEEK_SET = global i32 0
define i32 @id3_lseek_syncword(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i64 @xmallocd(i32 4096, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %4
%8 = load i32, i32* %3
%9 = load i32, i32* @SEEK_SET
%10 = call i32 @lseek(i32 %8, i32 %9, i32 0)
%11 = load i32, i32* %3
%12 = load i8*, i8** %4
%13 = call i32 @read(i32 %11, i8* %12, i32 4096)
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load i8*, i8** %4
%17 = call i32 @xfree(i8* %16)
store i32 0, i32* %2
br label %25
18: ; preds = %1
%19 = load i32, i32* %3
%20 = load i8*, i8** %4
%21 = call i32 @id3_lseek_syncword_r(i32 %19, i8* %20, i32 0)
store i32 %21, i32* %5
%22 = load i8*, i8** %4
%23 = call i32 @xfree(i8* %22)
%24 = load i32, i32* %5
store i32 %24, i32* %2
br label %25
25: ; preds = %18, %15
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [24 x i8] c"id3_lseek_syncword:data\00"
@SEEK_SET = global i32 0
define i32 @id3_lseek_syncword(i32 %0) {
%2 = tail call i64 @xmallocd(i32 4096, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%3 = inttoptr i64 %2 to i8*
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @lseek(i32 %0, i32 %4, i32 0)
%6 = tail call i32 @read(i32 %0, i8* %3, i32 4096)
%7 = icmp slt i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = tail call i32 @id3_lseek_syncword_r(i32 %0, i8* %3, i32 0)
br label %10
10: ; preds = %1, %8
%11 = phi i32 [ %9, %8 ], [ 0, %1 ]
%12 = tail call i32 @xfree(i8* %3)
ret i32 %11
}