#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 /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int id3_read_tag(const char *path, char *tag) {
  FILE *fp;
  int i;
  assert(path != NULL);
  assert(tag != NULL);
  if ((fp = fopen(path, "r")) == NULL)
    return (-1);
  if (fseek(fp, -1 * 128, SEEK_END) == -1)
    return (-1);
  for (i = 0; i < 128; i++) {
    tag[i] = fgetc(fp);
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<id3_read_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ae <id3_read_tag+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <id3_read_tag+0xd2>
mov    -0x20(%rbp),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    $0xffffff80,%esi
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
jne    11da <id3_read_tag+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <id3_read_tag+0xd2>
movl   $0x0,-0x24(%rbp)
cmpl   $0x80,-0x24(%rbp)
jge    1212 <id3_read_tag+0xc2>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e1 <id3_read_tag+0x91>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id3_read_tag>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     11d3 <id3_read_tag+0x83>
mov    %rax,%rbx
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffff80,%esi
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
je     11d3 <id3_read_tag+0x83>
xor    %ebp,%ebp
nop
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
cmp    $0x80,%rbp
jne    11b0 <id3_read_tag+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i32 @id3_read_tag(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %4
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 -1, i32* %3
br label %43
20: ; preds = %2
%21 = load i32*, i32** %6
%22 = load i32, i32* @SEEK_END
%23 = call i32 @fseek(i32* %21, i32 -128, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 -1, i32* %3
br label %43
26: ; preds = %20
store i32 0, i32* %7
br label %27
27: ; preds = %37, %26
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 128
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load i32*, i32** %6
%32 = call signext i8 @fgetc(i32* %31)
%33 = load i8*, i8** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
br label %37
37: ; preds = %30
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %27
40: ; preds = %27
%41 = load i32*, i32** %6
%42 = call i32 @fclose(i32* %41)
store i32 0, i32* %3
br label %43
43: ; preds = %40, %25, %19
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i32 @id3_read_tag(i8* %0, i8* writeonly %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne i8* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %23, label %11
11: ; preds = %2
%12 = load i32, i32* @SEEK_END
%13 = tail call i32 @fseek(i32* %9, i32 -128, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %23, label %15
15: ; preds = %11, %15
%16 = phi i64 [ %19, %15 ], [ 0, %11 ]
%17 = tail call signext i8 @fgetc(i32* %9)
%18 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 %17, i8* %18
%19 = add nuw nsw i64 %16, 1
%20 = icmp eq i64 %19, 128
br i1 %20, label %21, label %15
21: ; preds = %15
%22 = tail call i32 @fclose(i32* %9)
br label %23
23: ; preds = %11, %2, %21
%24 = phi i32 [ 0, %21 ], [ -1, %2 ], [ -1, %11 ]
ret i32 %24
}