#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 atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *rawfile;
  unsigned char block[49792];
  int ii, numwrite;
  if (argc != 4) {
    printf("\nusage:  taperaw blockfile tapefile number\n\n");
    printf("    'blockfile' is the file where we will steal the 1st block to "
           "tape\n");
    printf("    'tapefile' is the file where we will append the block\n");
    printf("    'number' is the number of times we will tape the block\n\n");
    printf("  This routine appends substitute blocks onto the end of a\n");
    printf("  raw Parkes Multibeam data file.  This is useful for\n");
    printf("  replacing a small number of blocks that are unusable\n");
    printf("  for one reason or another.\n\n");
    exit(0);
  }
  numwrite = atoi(argv[3]);
  printf("\nReading block from '%s' and appending it %d times to '%s'...\n\n",
         argv[1], numwrite, argv[2]);
  rawfile = fopen(argv[1], "rb");
  fread(block, sizeof(unsigned char), 49792, rawfile);
  fclose(rawfile);
  rawfile = fopen(argv[2], "ab");
  for (ii = 0; ii < numwrite; ii++)
    fwrite(block, sizeof(unsigned char), 49792, rawfile);
  printf("Done.\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc2b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     120a <main+0x9a>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0xc2a8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0xc2a8(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xf7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xfa6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0xc2a0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc280,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xf6e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc2a4(%rbp)
mov    -0xc2a4(%rbp),%eax
cmp    -0xc2a8(%rbp),%eax
jge    12de <main+0x16e>
lea    -0xc2a0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc280,%edx
call   1090 <fwrite@plt>
mov    -0xc2a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc2a4(%rbp)
jmp    129e <main+0x12e>
lea    0xf17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xc2b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xc280,%rsp
cmp    $0x4,%edi
jne    1245 <main+0xc5>
mov    %rsi,%r14
mov    0x18(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
mov    0x8(%r14),%rsi
mov    0x10(%r14),%rcx
lea    0xe4e(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%r14),%rdi
lea    0xe7a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0xc280,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    0x10(%r14),%rdi
lea    0xe4d(%rip),%rsi
call   1070 <fopen@plt>
test   %ebx,%ebx
jle    122a <main+0xaa>
mov    %rax,%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0xc280,%edx
mov    %r14,%rcx
call   10a0 <fwrite@plt>
add    $0xffffffff,%ebx
jne    1210 <main+0x90>
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xc280,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe01(%rip),%rdi
call   1030 <puts@plt>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
lea    0xf12(%rip),%rdi
call   1030 <puts@plt>
lea    0xf3d(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"\0Ausage: taperaw blockfile tapefile number\0A\0A\00"
@.str.1 = [71 x i8] c" 'blockfile' is the file where we will steal the 1st block to tape\0A\00"
@.str.2 = [59 x i8] c" 'tapefile' is the file where we will append the block\0A\00"
@.str.3 = [61 x i8] c" 'number' is the number of times we will tape the block\0A\0A\00"
@.str.4 = [60 x i8] c" This routine appends substitute blocks onto the end of a\0A\00"
@.str.5 = [55 x i8] c" raw Parkes Multibeam data file. This is useful for\0A\00"
@.str.6 = [56 x i8] c" replacing a small number of blocks that are unusable\0A\00"
@.str.7 = [31 x i8] c" for one reason or another.\0A\0A\00"
@.str.8 = [64 x i8] c"\0AReading block from '%s' and appending it %d times to '%s'...\0A\0A\00"
@.str.9 = [3 x i8] c"rb\00"
@.str.10 = [3 x i8] c"ab\00"
@.str.11 = [8 x i8] c"Done.\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [49792 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %22
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 3
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %9
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i32, i32* %9
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.8, i64 0, i64 0), i8* %29, i32 %30, i8* %33)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
store i32* %38, i32** %6
%39 = getelementptr inbounds [49792 x i8], [49792 x i8]* %7, i64 0, i64 0
%40 = load i32*, i32** %6
%41 = call i32 @fread(i8* %39, i32 1, i32 49792, i32* %40)
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
store i32* %47, i32** %6
store i32 0, i32* %8
br label %48
48: ; preds = %56, %22
%49 = load i32, i32* %8
%50 = load i32, i32* %9
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %59
52: ; preds = %48
%53 = getelementptr inbounds [49792 x i8], [49792 x i8]* %7, i64 0, i64 0
%54 = load i32*, i32** %6
%55 = call i32 @fwrite(i8* %53, i32 1, i32 49792, i32* %54)
br label %56
56: ; preds = %52
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %48
59: ; preds = %48
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.8 = [64 x i8] c"\0AReading block from '%s' and appending it %d times to '%s'...\0A\0A\00"
@.str.9 = [3 x i8] c"rb\00"
@.str.10 = [3 x i8] c"ab\00"
@str = [7 x i8] c"Done.\0A\00"
@str.12 = [44 x i8] c"\0Ausage: taperaw blockfile tapefile number\0A\00"
@str.13 = [70 x i8] c" 'blockfile' is the file where we will steal the 1st block to tape\00"
@str.14 = [58 x i8] c" 'tapefile' is the file where we will append the block\00"
@str.15 = [60 x i8] c" 'number' is the number of times we will tape the block\0A\00"
@str.16 = [59 x i8] c" This routine appends substitute blocks onto the end of a\00"
@str.17 = [54 x i8] c" raw Parkes Multibeam data file. This is useful for\00"
@str.18 = [55 x i8] c" replacing a small number of blocks that are unusable\00"
@str.19 = [30 x i8] c" for one reason or another.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [49792 x i8]
%4 = getelementptr inbounds [49792 x i8], [49792 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.12, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.13, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.14, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.15, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.16, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.17, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.18, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.19, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.8, i64 0, i64 0), i8* %21, i32 %19, i8* %23)
%25 = load i8*, i8** %20
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%27 = call i32 @fread(i8* %4, i32 1, i32 49792, i32* %26)
%28 = tail call i32 @fclose(i32* %26)
%29 = load i8*, i8** %22
%30 = tail call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%31 = icmp sgt i32 %19, 0
br i1 %31, label %32, label %37
32: ; preds = %16, %32
%33 = phi i32 [ %35, %32 ], [ 0, %16 ]
%34 = call i32 @fwrite(i8* %4, i32 1, i32 49792, i32* %30)
%35 = add nuw nsw i32 %33, 1
%36 = icmp eq i32 %35, %19
br i1 %36, label %37, label %32
37: ; preds = %32, %16
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
ret i32 0
}