#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*/ copytrack_verbatim();
int /*<<< orphan*/ mf_write_track_chunk(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ replace_byte_in_trackdata(int, char);
void replace_byte_in_file(int trknum, int loc, char val, FILE *fp,
                          int ntracks) {
  int i;
  for (i = 0; i < ntracks; i++) {
    copytrack_verbatim();
    if (i == trknum)
      replace_byte_in_trackdata(loc, val);
    mf_write_track_chunk(i, fp);
  }
}


x86 assembly (clang, -O0):
<replace_byte_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1197 <replace_byte_in_file+0x67>
mov    $0x0,%al
call   1050 <copytrack_verbatim@plt>
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    117d <replace_byte_in_file+0x4d>
mov    -0x8(%rbp),%edi
movsbl -0x9(%rbp),%esi
call   1030 <replace_byte_in_trackdata@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <mf_write_track_chunk@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1152 <replace_byte_in_file+0x22>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_byte_in_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %r8d,%r8d
jle    118a <replace_byte_in_file+0x5a>
mov    %r8d,%r13d
mov    %rcx,%r14
mov    %esi,%r15d
mov    %edi,%ebp
movsbl %dl,%r12d
xor    %ebx,%ebx
jmp    1172 <replace_byte_in_file+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <mf_write_track_chunk@plt>
add    $0x1,%ebx
cmp    %ebx,%r13d
je     118a <replace_byte_in_file+0x5a>
xor    %eax,%eax
call   1050 <copytrack_verbatim@plt>
cmp    %ebx,%ebp
jne    1160 <replace_byte_in_file+0x30>
mov    %r15d,%edi
mov    %r12d,%esi
call   1030 <replace_byte_in_trackdata@plt>
jmp    1160 <replace_byte_in_file+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @replace_byte_in_file(i32 %0, i32 %1, i8 signext %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8 %2, i8* %8
store i32* %3, i32** %9
store i32 %4, i32* %10
store i32 0, i32* %11
br label %12
12: ; preds = %29, %5
%13 = load i32, i32* %11
%14 = load i32, i32* %10
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = call i32 (...) @copytrack_verbatim()
%18 = load i32, i32* %11
%19 = load i32, i32* %6
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* %7
%23 = load i8, i8* %8
%24 = call i32 @replace_byte_in_trackdata(i32 %22, i8 signext %23)
br label %25
25: ; preds = %21, %16
%26 = load i32, i32* %11
%27 = load i32*, i32** %9
%28 = call i32 @mf_write_track_chunk(i32 %26, i32* %27)
br label %29
29: ; preds = %25
%30 = load i32, i32* %11
%31 = add nsw i32 %30, 1
store i32 %31, i32* %11
br label %12
32: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @replace_byte_in_file(i32 %0, i32 %1, i8 signext %2, i32* %3, i32 %4) {
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %17
7: ; preds = %5, %13
%8 = phi i32 [ %15, %13 ], [ 0, %5 ]
%9 = tail call i32 (...) @copytrack_verbatim()
%10 = icmp eq i32 %8, %0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @replace_byte_in_trackdata(i32 %1, i8 signext %2)
br label %13
13: ; preds = %11, %7
%14 = tail call i32 @mf_write_track_chunk(i32 %8, i32* %3)
%15 = add nuw nsw i32 %8, 1
%16 = icmp eq i32 %15, %4
br i1 %16, label %17, label %7
17: ; preds = %13, %5
ret void
}