#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 */
struct stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
scalar_t__ fstat(int, struct stat *);
scalar_t__ ftruncate(int, int);
int lseek(int, long, int /*<<< orphan*/);
int read(int, unsigned char *, int);
scalar_t__ strncmp(unsigned char *, char *, int);
int /*<<< orphan*/ xfree(unsigned char *);
scalar_t__ xmallocd(int, char *);
int id3v1_del_tag(int fd) {
  int nlength;
  unsigned char *c;
  struct stat fs;
  if (fstat(fd, &fs))
    return 1;
  if (fs.st_size < 128)
    return 1;
  c = (char *)xmallocd(3, "id3v1_del_tag:c");
  if (lseek(fd, -128L, SEEK_END) == -1)
    goto exit_on_error;
  if (read(fd, c, 3) < 3)
    goto exit_on_error;
  if (strncmp(c, "TAG", 3))
    goto exit_on_error;
  xfree(c);
  nlength = fs.st_size - 128;
  if (ftruncate(fd, nlength))
    return 1;
  return 0;
exit_on_error:
  xfree(c);
  return 1;
}


x86 assembly (clang, -O0):
<id3v1_del_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1090 <fstat@plt>
cmp    $0x0,%rax
je     119d <id3v1_del_tag+0x2d>
movl   $0x1,-0x4(%rbp)
jmp    1285 <id3v1_del_tag+0x115>
cmpl   $0x80,-0x20(%rbp)
jge    11b6 <id3v1_del_tag+0x46>
movl   $0x1,-0x4(%rbp)
jmp    1285 <id3v1_del_tag+0x115>
mov    $0x3,%edi
lea    0xe3e(%rip),%rsi
call   1080 <xmallocd@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffffffffff80,%rsi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11f1 <id3v1_del_tag+0x81>
jmp    1275 <id3v1_del_tag+0x105>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x3,%edx
call   1070 <read@plt>
cmp    $0x3,%eax
jge    1210 <id3v1_del_tag+0xa0>
jmp    1275 <id3v1_del_tag+0x105>
mov    -0x18(%rbp),%rdi
lea    0xdf5(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1234 <id3v1_del_tag+0xc4>
jmp    1275 <id3v1_del_tag+0x105>
mov    -0x18(%rbp),%rdi
call   1040 <xfree@plt>
mov    -0x20(%rbp),%eax
sub    $0x80,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <ftruncate@plt>
cmp    $0x0,%rax
je     1269 <id3v1_del_tag+0xf9>
movl   $0x1,-0x4(%rbp)
jmp    1285 <id3v1_del_tag+0x115>
movl   $0x0,-0x4(%rbp)
jmp    1285 <id3v1_del_tag+0x115>
mov    -0x18(%rbp),%rdi
call   1040 <xfree@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id3v1_del_tag>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %rsp,%rsi
call   1090 <fstat@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    11fd <id3v1_del_tag+0x8d>
mov    (%rsp),%r14d
cmp    $0x80,%r14d
jl     11fd <id3v1_del_tag+0x8d>
lea    0xe61(%rip),%rsi
mov    $0x3,%edi
call   1080 <xmallocd@plt>
mov    %rax,%r15
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0xffffffffffffff80,%rsi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     11f5 <id3v1_del_tag+0x85>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x3,%edx
call   1070 <read@plt>
cmp    $0x3,%eax
jl     11f5 <id3v1_del_tag+0x85>
lea    0xe2d(%rip),%rsi
mov    %r15,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     120a <id3v1_del_tag+0x9a>
mov    %r15,%rdi
call   1040 <xfree@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1040 <xfree@plt>
add    $0xffffff80,%r14d
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <ftruncate@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
jmp    11fd <id3v1_del_tag+0x8d>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [16 x i8] c"id3v1_del_tag:c\00"
@SEEK_END = global i32 0
@.str.1 = [4 x i8] c"TAG\00"
define i32 @id3v1_del_tag(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.stat
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = call i64 @fstat(i32 %7, %struct.stat* %6)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1, i32* %2
br label %50
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%13 = load i32, i32* %12
%14 = icmp slt i32 %13, 128
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 1, i32* %2
br label %50
16: ; preds = %11
%17 = call i64 @xmallocd(i32 3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %5
%19 = load i32, i32* %3
%20 = load i32, i32* @SEEK_END
%21 = call i32 @lseek(i32 %19, i64 -128, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %16
br label %47
24: ; preds = %16
%25 = load i32, i32* %3
%26 = load i8*, i8** %5
%27 = call i32 @read(i32 %25, i8* %26, i32 3)
%28 = icmp slt i32 %27, 3
br i1 %28, label %29, label %30
29: ; preds = %24
br label %47
30: ; preds = %24
%31 = load i8*, i8** %5
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
br label %47
35: ; preds = %30
%36 = load i8*, i8** %5
%37 = call i32 @xfree(i8* %36)
%38 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%39 = load i32, i32* %38
%40 = sub nsw i32 %39, 128
store i32 %40, i32* %4
%41 = load i32, i32* %3
%42 = load i32, i32* %4
%43 = call i64 @ftruncate(i32 %41, i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %35
store i32 1, i32* %2
br label %50
46: ; preds = %35
store i32 0, i32* %2
br label %50
47: ; preds = %34, %29, %23
%48 = load i8*, i8** %5
%49 = call i32 @xfree(i8* %48)
store i32 1, i32* %2
br label %50
50: ; preds = %47, %46, %45, %15, %10
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [16 x i8] c"id3v1_del_tag:c\00"
@SEEK_END = global i32 0
@.str.1 = [4 x i8] c"TAG\00"
define i32 @id3v1_del_tag(i32 %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @fstat(i32 %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %30
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp slt i32 %8, 128
br i1 %9, label %30, label %10
10: ; preds = %6
%11 = tail call i64 @xmallocd(i32 3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = inttoptr i64 %11 to i8*
%13 = load i32, i32* @SEEK_END
%14 = tail call i32 @lseek(i32 %0, i64 -128, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %28, label %16
16: ; preds = %10
%17 = tail call i32 @read(i32 %0, i8* %12, i32 3)
%18 = icmp slt i32 %17, 3
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = tail call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = tail call i32 @xfree(i8* %12)
%24 = add nsw i32 %8, -128
%25 = tail call i64 @ftruncate(i32 %0, i32 %24)
%26 = icmp ne i64 %25, 0
%27 = zext i1 %26 to i32
br label %30
28: ; preds = %19, %16, %10
%29 = tail call i32 @xfree(i8* %12)
br label %30
30: ; preds = %22, %6, %1, %28
%31 = phi i32 [ 1, %28 ], [ 1, %1 ], [ 1, %6 ], [ %27, %22 ]
ret i32 %31
}