#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 */
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(unsigned char *, char *);
int finddatachunk(FILE *file) {
  unsigned char data[5];
  unsigned char cdlen[5];
  int dlen;
  int dafound = 0;
  data[2] = 0;
  while (fread(data, 2, 1, file) == 1) {
    if (!strcmp(data, "ta")) {
      if (dafound) {
        fread(cdlen, 4, 1, file);
        dlen = cdlen[0] + ((int)(cdlen[1]) << 8) + ((int)(cdlen[2]) << 16) +
               ((int)(cdlen[3]) << 24);
        return dlen;
      } else
        dafound = 0;
    } else if (!strcmp(data, "da")) {
      dafound = 1;
      continue;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<finddatachunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movb   $0x0,-0x13(%rbp)
lea    -0x15(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11f9 <finddatachunk+0xd9>
lea    -0x15(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11ca <finddatachunk+0xaa>
cmpl   $0x0,-0x24(%rbp)
je     11be <finddatachunk+0x9e>
lea    -0x1a(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
movzbl -0x1a(%rbp),%eax
movzbl -0x19(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
movzbl -0x18(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
movzbl -0x17(%rbp),%ecx
shl    $0x18,%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1200 <finddatachunk+0xe0>
movl   $0x0,-0x24(%rbp)
jmp    11f4 <finddatachunk+0xd4>
lea    -0x15(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11ef <finddatachunk+0xcf>
movl   $0x1,-0x24(%rbp)
jmp    1137 <finddatachunk+0x17>
jmp    11f4 <finddatachunk+0xd4>
jmp    1137 <finddatachunk+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finddatachunk>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movb   $0x0,0x8(%rsp)
lea    0x6(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    11c1 <finddatachunk+0xb1>
xor    %ebp,%ebp
lea    0x6(%rsp),%r14
jmp    1173 <finddatachunk+0x63>
nopl   (%rax)
test   %ebp,%ebp
mov    $0x0,%ebp
jne    11a6 <finddatachunk+0x96>
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11a2 <finddatachunk+0x92>
movzwl 0x6(%rsp),%eax
xor    $0x6174,%eax
movzbl 0x8(%rsp),%ecx
or     %ax,%cx
je     1150 <finddatachunk+0x40>
movzwl 0x6(%rsp),%eax
xor    $0x6164,%eax
movzbl 0x8(%rsp),%ecx
or     %ax,%cx
jne    1159 <finddatachunk+0x49>
mov    $0x1,%ebp
jmp    1159 <finddatachunk+0x49>
xor    %eax,%eax
jmp    11c1 <finddatachunk+0xb1>
lea    0xb(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0xb(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ta\00"
@.str.1 = [3 x i8] c"da\00"
define i32 @finddatachunk(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [5 x i8]
%5 = alloca [5 x i8]
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %7
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 2
store i8 0, i8* %8
br label %9
9: ; preds = %52, %50, %1
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i32 @fread(i8* %10, i32 2, i32 1, i32* %11)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %53
14: ; preds = %9
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %46, label %18
18: ; preds = %14
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %44
21: ; preds = %18
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%23 = load i32*, i32** %3
%24 = call i32 @fread(i8* %22, i32 4, i32 1, i32* %23)
%25 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 1
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = shl i32 %30, 8
%32 = add nsw i32 %27, %31
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 2
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = shl i32 %35, 16
%37 = add nsw i32 %32, %36
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 3
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = shl i32 %40, 24
%42 = add nsw i32 %37, %41
store i32 %42, i32* %6
%43 = load i32, i32* %6
store i32 %43, i32* %2
br label %54
44: ; preds = %18
store i32 0, i32* %7
br label %45
45: ; preds = %44
br label %52
46: ; preds = %14
%47 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%48 = call i32 @strcmp(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%49 = icmp ne i32 %48, 0
br i1 %49, label %51, label %50
50: ; preds = %46
store i32 1, i32* %7
br label %9
51: ; preds = %46
br label %52
52: ; preds = %51, %45
br label %9
53: ; preds = %9
store i32 0, i32* %2
br label %54
54: ; preds = %53, %21
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"ta\00"
@.str.1 = [3 x i8] c"da\00"
define i32 @finddatachunk(i32* nocapture %0) {
%2 = alloca [5 x i8]
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 2
store i8 0, i8* %6
%7 = call i32 @fread(i8* %4, i32 2, i32 1, i32* %0)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %43
9: ; preds = %1, %39
%10 = phi i32 [ %40, %39 ], [ 0, %1 ]
%11 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = icmp eq i32 %10, 0
br i1 %14, label %37, label %15
15: ; preds = %13
%16 = call i32 @fread(i8* %5, i32 4, i32 1, i32* %0)
%17 = load i8, i8* %5
%18 = zext i8 %17 to i32
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 1
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = shl nuw nsw i32 %21, 8
%23 = or i32 %22, %18
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 2
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = shl nuw nsw i32 %26, 16
%28 = or i32 %23, %27
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 3
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = shl nuw i32 %31, 24
%33 = or i32 %28, %32
br label %43
34: ; preds = %9
%35 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 3)
%36 = icmp eq i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %13, %34
%38 = phi i32 [ %10, %34 ], [ 0, %13 ]
br label %39
39: ; preds = %37, %34
%40 = phi i32 [ %38, %37 ], [ 1, %34 ]
%41 = call i32 @fread(i8* %4, i32 2, i32 1, i32* %0)
%42 = icmp eq i32 %41, 1
br i1 %42, label %9, label %43
43: ; preds = %39, %1, %15
%44 = phi i32 [ %33, %15 ], [ 0, %1 ], [ 0, %39 ]
ret i32 %44
}