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

/* Variables and functions */
int read(int, char *, int);
int /*<<< orphan*/ trace(char *, int);
int flv_open_ic(int flv_fd) {
  int ret = 0;
  char h[13];
  if (read(flv_fd, h, sizeof(h)) != sizeof(h)) {
    ret = -1;
    trace("read flv header failed. ret=%d", ret);
    return ret;
  }
  if (h[0] != 'F' || h[1] != 'L' || h[2] != 'V') {
    ret = -1;
    trace("input is not a flv file. ret=%d", ret);
    return ret;
  }
  return ret;
}


x86 assembly (clang, -O0):
<flv_open_ic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0xd,%edx
call   1030 <read@plt>
cltq
cmp    $0xd,%rax
je     1170 <flv_open_ic+0x50>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea0(%rip),%rdi
call   1040 <trace@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <flv_open_ic+0x9e>
movsbl -0x19(%rbp),%eax
cmp    $0x46,%eax
jne    1197 <flv_open_ic+0x77>
movsbl -0x18(%rbp),%eax
cmp    $0x4c,%eax
jne    1197 <flv_open_ic+0x77>
movsbl -0x17(%rbp),%eax
cmp    $0x56,%eax
je     11b8 <flv_open_ic+0x98>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe77(%rip),%rdi
call   1040 <trace@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <flv_open_ic+0x9e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flv_open_ic>:
push   %rbx
sub    $0x10,%rsp
lea    0x3(%rsp),%rsi
mov    $0xd,%edx
call   1030 <read@plt>
cmp    $0xd,%eax
jne    1159 <flv_open_ic+0x39>
cmpb   $0x46,0x3(%rsp)
lea    0xeda(%rip),%rdi
jne    1160 <flv_open_ic+0x40>
cmpb   $0x4c,0x4(%rsp)
jne    1160 <flv_open_ic+0x40>
xor    %ebx,%ebx
cmpb   $0x56,0x5(%rsp)
je     116f <flv_open_ic+0x4f>
jmp    1160 <flv_open_ic+0x40>
lea    0xea0(%rip),%rdi
mov    $0xffffffff,%ebx
mov    $0xffffffff,%esi
call   1040 <trace@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"read flv header failed. ret=%d\00"
@.str.1 = [32 x i8] c"input is not a flv file. ret=%d\00"
define i32 @flv_open_ic(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [13 x i8]
store i32 %0, i32* %3
store i32 0, i32* %4
%6 = load i32, i32* %3
%7 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 13)
%9 = sext i32 %8 to i64
%10 = icmp ne i64 %9, 13
br i1 %10, label %11, label %15
11: ; preds = %1
store i32 -1, i32* %4
%12 = load i32, i32* %4
%13 = call i32 @trace(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %4
store i32 %14, i32* %2
br label %36
15: ; preds = %1
%16 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 70
br i1 %19, label %30, label %20
20: ; preds = %15
%21 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 76
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 2
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 86
br i1 %29, label %30, label %34
30: ; preds = %25, %20, %15
store i32 -1, i32* %4
%31 = load i32, i32* %4
%32 = call i32 @trace(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
store i32 %33, i32* %2
br label %36
34: ; preds = %25
%35 = load i32, i32* %4
store i32 %35, i32* %2
br label %36
36: ; preds = %34, %30, %11
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [31 x i8] c"read flv header failed. ret=%d\00"
@.str.1 = [32 x i8] c"input is not a flv file. ret=%d\00"
define i32 @flv_open_ic(i32 %0) {
%2 = alloca [13 x i8]
%3 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 13)
%5 = icmp eq i32 %4, 13
br i1 %5, label %6, label %17
6: ; preds = %1
%7 = load i8, i8* %3
%8 = icmp ne i8 %7, 70
%9 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 1
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 76
%12 = select i1 %8, i1 true, i1 %11
%13 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 2
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 86
%16 = select i1 %12, i1 true, i1 %15
br i1 %16, label %17, label %20
17: ; preds = %6, %1
%18 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), %6 ]
%19 = tail call i32 @trace(i8* %18, i32 -1)
br label %20
20: ; preds = %17, %6
%21 = phi i32 [ 0, %6 ], [ -1, %17 ]
ret i32 %21
}