#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 int32_t;
typedef int /*<<< orphan*/ id;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ ferror(int /*<<< orphan*/ *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
void sauce_read_comments(FILE *fd, char **comment, int32_t comments) {
  int32_t i;
  char id[6];
  long offset = 128 + 5 + 64 * comments;
  if (!fseek(fd, 0 - offset, SEEK_END)) {
    free(comment);
    return;
  }
  if (fread(id, sizeof(id) - 1, 1, fd) == 0) {
    return;
  }
  id[sizeof(id) - 1] = 0x00;
  if (strcmp(id, "COMNT")) {
    free(comment);
    return;
  }
  for (i = 0; i < comments; ++i) {
    char buf[64 + 1];
    memset(buf, 0, sizeof(buf));
    if (fread(buf, 64, 1, fd) == 0) {
      free(comment);
      return;
    }
    buf[64] = 0x00;
    if (!ferror(fd)) {
      comment[i] = strdup(buf);
      if (comment[i] == NULL) {
        free(comment);
        return;
      }
    } else {
      free(comment);
      return;
    }
  }
}


x86 assembly (clang, -O0):
<sauce_read_comments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x6,%eax
add    $0x85,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
sub    -0x28(%rbp),%rsi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
cmp    $0x0,%eax
jne    11c5 <sauce_read_comments+0x55>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    12de <sauce_read_comments+0x16e>
lea    -0x1e(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x5,%esi
mov    $0x1,%edx
call   1050 <fread@plt>
cmp    $0x0,%rax
jne    11eb <sauce_read_comments+0x7b>
jmp    12de <sauce_read_comments+0x16e>
movb   $0x0,-0x19(%rbp)
lea    -0x1e(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1217 <sauce_read_comments+0xa7>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    12de <sauce_read_comments+0x16e>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12de <sauce_read_comments+0x16e>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1060 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x40,%esi
mov    $0x1,%edx
call   1050 <fread@plt>
cmp    $0x0,%rax
jne    1269 <sauce_read_comments+0xf9>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    12de <sauce_read_comments+0x16e>
movb   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%eax
jne    12bd <sauce_read_comments+0x14d>
lea    -0x70(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    12b8 <sauce_read_comments+0x148>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    12de <sauce_read_comments+0x16e>
jmp    12cb <sauce_read_comments+0x15b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    12de <sauce_read_comments+0x16e>
jmp    12d0 <sauce_read_comments+0x160>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    121e <sauce_read_comments+0xae>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sauce_read_comments>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%eax
shl    $0x6,%eax
mov    $0xffffff7b,%ecx
sub    %eax,%ecx
movslq %ecx,%rsi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
test   %eax,%eax
je     11f1 <sauce_read_comments+0x81>
lea    0xa(%rsp),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     11e4 <sauce_read_comments+0x74>
movb   $0x0,0xf(%rsp)
lea    0xe33(%rip),%rsi
lea    0xa(%rsp),%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1205 <sauce_read_comments+0x95>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
test   %ebp,%ebp
jle    11e4 <sauce_read_comments+0x74>
mov    %ebp,%r15d
xor    %ebp,%ebp
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1060 <memset@plt>
mov    %r12,%rdi
mov    $0x40,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     11dc <sauce_read_comments+0x6c>
movb   $0x0,0x50(%rsp)
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %eax,%eax
jne    11dc <sauce_read_comments+0x6c>
mov    %r12,%rdi
call   1090 <strdup@plt>
mov    %rax,(%r14,%rbp,8)
test   %rax,%rax
je     11dc <sauce_read_comments+0x6c>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1220 <sauce_read_comments+0xb0>
jmp    11e4 <sauce_read_comments+0x74>

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [6 x i8] c"COMNT\00"
define void @sauce_read_comments(i32* %0, i8** %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [6 x i8]
%9 = alloca i64
%10 = alloca [65 x i8]
store i32* %0, i32** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = mul nsw i32 64, %11
%13 = add nsw i32 133, %12
%14 = sext i32 %13 to i64
store i64 %14, i64* %9
%15 = load i32*, i32** %4
%16 = load i64, i64* %9
%17 = sub nsw i64 0, %16
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %15, i64 %17, i32 %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %3
%22 = load i8**, i8*** %5
%23 = call i32 @free(i8** %22)
br label %82
24: ; preds = %3
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%26 = load i32*, i32** %4
%27 = call i64 @fread(i8* %25, i32 5, i32 1, i32* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
br label %82
30: ; preds = %24
%31 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 5
store i8 0, i8* %31
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i8**, i8*** %5
%37 = call i32 @free(i8** %36)
br label %82
38: ; preds = %30
store i32 0, i32* %7
br label %39
39: ; preds = %79, %38
%40 = load i32, i32* %7
%41 = load i32, i32* %6
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %82
43: ; preds = %39
%44 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%45 = call i32 @memset(i8* %44, i32 0, i32 65)
%46 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%47 = load i32*, i32** %4
%48 = call i64 @fread(i8* %46, i32 64, i32 1, i32* %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %43
%51 = load i8**, i8*** %5
%52 = call i32 @free(i8** %51)
br label %82
53: ; preds = %43
%54 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 64
store i8 0, i8* %54
%55 = load i32*, i32** %4
%56 = call i32 @ferror(i32* %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %75, label %58
58: ; preds = %53
%59 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%60 = call i8* @strdup(i8* %59)
%61 = load i8**, i8*** %5
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
store i8* %60, i8** %64
%65 = load i8**, i8*** %5
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
%69 = load i8*, i8** %68
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %74
71: ; preds = %58
%72 = load i8**, i8*** %5
%73 = call i32 @free(i8** %72)
br label %82
74: ; preds = %58
br label %78
75: ; preds = %53
%76 = load i8**, i8*** %5
%77 = call i32 @free(i8** %76)
br label %82
78: ; preds = %74
br label %79
79: ; preds = %78
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
store i32 %81, i32* %7
br label %39
82: ; preds = %21, %29, %35, %50, %71, %75, %39
ret void
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [6 x i8] c"COMNT\00"
define void @sauce_read_comments(i32* nocapture %0, i8** nocapture %1, i32 %2) {
%4 = alloca [6 x i8]
%5 = alloca [65 x i8]
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%7 = mul i32 %2, -64
%8 = add i32 %7, -133
%9 = sext i32 %8 to i64
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %0, i64 %9, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call i32 @free(i8** %1)
br label %51
15: ; preds = %3
%16 = call i64 @fread(i8* %6, i32 5, i32 1, i32* %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %51, label %18
18: ; preds = %15
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 5
store i8 0, i8* %19
%20 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = icmp sgt i32 %2, 0
br i1 %23, label %24, label %51
24: ; preds = %22
%25 = getelementptr inbounds [65 x i8], [65 x i8]* %5, i64 0, i64 0
%26 = getelementptr inbounds [65 x i8], [65 x i8]* %5, i64 0, i64 64
%27 = zext i32 %2 to i64
br label %30
28: ; preds = %18
%29 = call i32 @free(i8** %1)
br label %51
30: ; preds = %24, %48
%31 = phi i64 [ 0, %24 ], [ %49, %48 ]
%32 = call i32 @memset(i8* %25, i32 0, i32 65)
%33 = call i64 @fread(i8* %25, i32 64, i32 1, i32* %0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @free(i8** %1)
br label %51
37: ; preds = %30
store i8 0, i8* %26
%38 = call i32 @ferror(i32* %0)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = call i8* @strdup(i8* %25)
%42 = getelementptr inbounds i8*, i8** %1, i64 %31
store i8* %41, i8** %42
%43 = icmp eq i8* %41, null
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = call i32 @free(i8** %1)
br label %51
46: ; preds = %37
%47 = call i32 @free(i8** %1)
br label %51
48: ; preds = %40
%49 = add nuw nsw i64 %31, 1
%50 = icmp eq i64 %49, %27
br i1 %50, label %51, label %30
51: ; preds = %48, %22, %35, %44, %46, %15, %28, %13
ret void
}