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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 4) {
    fprintf(stderr, "usage: %s [in filename] [number] [out filename]\n",
            argv[0]);
    exit(EXIT_FAILURE);
  }
  FILE *input = fopen(argv[1], "rb");
  if (input == NULL) {
    fprintf(stderr, "failed to open file %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  FILE *output = fopen(argv[3], "wb");
  if (output == NULL) {
    fprintf(stderr, "failed to create file %s\n", argv[2]);
    exit(EXIT_FAILURE);
  }
  int8_t num = atoi(argv[2]);
  fwrite(&num, sizeof(int8_t), 1, output);
  int8_t c = 0;
  while (fread(&c, sizeof(int8_t), 1, input)) {
    fwrite(&c, sizeof(int8_t), 1, output);
  }
  printf("done\n");
  fclose(input);
  fclose(output);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11ca <main+0x4a>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe58(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1218 <main+0x98>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2f(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe25(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1266 <main+0xe6>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdfc(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     12d1 <main+0x151>
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
jmp    1294 <main+0x114>
lea    0xd91(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x3,%edi
jle    1279 <main+0xf9>
mov    0x8(%r15),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     128e <main+0x10e>
mov    %rax,%r14
mov    0x18(%r15),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12a4 <main+0x124>
mov    %rax,%r12
mov    0x10(%r15),%rdi
call   1080 <atoi@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
movl   $0x0,(%rsp)
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     124f <main+0xcf>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jne    1220 <main+0xa0>
lea    0xe13(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xd74(%rip),%rsi
jmp    12b8 <main+0x138>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xd92(%rip),%rsi
jmp    12b8 <main+0x138>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r15),%rdx
lea    0xd97(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"usage: %s [in filename] [number] [out filename]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [24 x i8] c"failed to open file %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [26 x i8] c"failed to create file %s\0A\00"
@.str.5 = [6 x i8] c"done\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%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 slt i32 %10, 4
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %35
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %20
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 3
%38 = load i8*, i8** %37
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %7
%40 = load i32*, i32** %7
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %50
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %35
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %8
%55 = load i32*, i32** %7
%56 = call i32 @fwrite(i32* %8, i32 4, i32 1, i32* %55)
store i32 0, i32* %9
br label %57
57: ; preds = %61, %50
%58 = load i32*, i32** %6
%59 = call i64 @fread(i32* %9, i32 4, i32 1, i32* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load i32*, i32** %7
%63 = call i32 @fwrite(i32* %9, i32 4, i32 1, i32* %62)
br label %57
64: ; preds = %57
%65 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
%68 = load i32*, i32** %7
%69 = call i32 @fclose(i32* %68)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"usage: %s [in filename] [number] [out filename]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [24 x i8] c"failed to open file %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [26 x i8] c"failed to create file %s\0A\00"
@str = [5 x i8] c"done\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = icmp slt i32 %0, 4
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %13
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = getelementptr inbounds i8*, i8** %1, i64 3
%25 = load i8*, i8** %24
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = getelementptr inbounds i8*, i8** %1, i64 2
%31 = load i8*, i8** %30
%32 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %23
%36 = bitcast i32* %3 to i8*
%37 = getelementptr inbounds i8*, i8** %1, i64 2
%38 = load i8*, i8** %37
%39 = tail call i32 @atoi(i8* %38)
store i32 %39, i32* %3
%40 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %26)
%41 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%42 = call i64 @fread(i32* %4, i32 4, i32 1, i32* %15)
%43 = icmp eq i64 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %35, %44
%45 = call i32 @fwrite(i32* %4, i32 4, i32 1, i32* %26)
%46 = call i64 @fread(i32* %4, i32 4, i32 1, i32* %15)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %44
48: ; preds = %44, %35
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%50 = tail call i32 @fclose(i32* %15)
%51 = tail call i32 @fclose(i32* %26)
ret i32 0
}