#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 */
char EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (argc > 1 && !strcmp(argv[1], "-s")) {
    FILE *in = fopen("tt", "rb");
    fseek(in, -4, SEEK_END);
    int size;
    fread(&size, 1, 4, in);
    int size_all;
    fseek(in, 0, SEEK_END);
    size_all = ftell(in);
    fseek(in, size, SEEK_SET);
    int i;
    for (i = size; i < size_all - 4; i++)
      putchar(fgetc(in));
    fclose(in);
    return 0;
  }
  FILE *in = fopen("tt.c", "rb");
  if (in) {
    FILE *out = fopen("tt", "ab");
    int size = ftell(out);
    char ch;
    while ((ch = fgetc(in)) != EOF)
      fputc(ch, out);
    fwrite(&size, 1, 4, out);
    fclose(out);
    fclose(in);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    12a2 <main+0x102>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe31(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12a2 <main+0x102>
lea    0xe1f(%rip),%rdi
lea    0xe1b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffc,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2d80(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x4,%ecx
cmp    %ecx,%eax
jge    128d <main+0xed>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    125d <main+0xbd>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    134c <main+0x1ac>
lea    0xd60(%rip),%rdi
lea    0xd56(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1345 <main+0x1a5>
lea    0xd38(%rip),%rdi
lea    0xd3c(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x3d(%rbp)
movsbl %al,%eax
mov    0x2ce3(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     131c <main+0x17c>
mov    -0x3d(%rbp),%al
mov    -0x38(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
jmp    12e7 <main+0x147>
mov    -0x38(%rbp),%rcx
lea    -0x3c(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10c0 <fwrite@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jl     11c5 <main+0x25>
mov    0x8(%rsi),%rdi
lea    0xe48(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     126a <main+0xca>
lea    0xe3d(%rip),%rdi
lea    0xe33(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     125f <main+0xbf>
mov    %rax,%r14
lea    0xe18(%rip),%rdi
lea    0xe1c(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <ftell@plt>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2dcb(%rip),%rbp
cmp    0x0(%rbp),%al
je     1238 <main+0x98>
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%rbp),%al
jne    1220 <main+0x80>
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd92(%rip),%rdi
lea    0xd8e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    0x2d61(%rip),%rbx
mov    (%rbx),%edx
mov    %rax,%rdi
mov    $0xfffffffc,%esi
call   10a0 <fseek@plt>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    (%rbx),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r14,%rdi
call   1090 <ftell@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%ebp
mov    0x2d02(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   10a0 <fseek@plt>
lea    -0x4(%rbx),%eax
cmp    %eax,%ebp
jge    1257 <main+0xb7>
sub    %ebp,%ebx
add    $0xfffffffc,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <fgetc@plt>
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    12f0 <main+0x150>
jmp    1257 <main+0xb7>

LLVM IR (-O0):
@.str = [3 x i8] c"-s\00"
@.str.1 = [3 x i8] c"tt\00"
@.str.2 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c"tt.c\00"
@.str.4 = [3 x i8] c"ab\00"
@EOF = global i8 0
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
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %54
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %54, label %22
22: ; preds = %16
%23 = call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = load i32, i32* @SEEK_END
%26 = call i32 @fseek(i32* %24, i32 -4, i32 %25)
%27 = load i32*, i32** %6
%28 = call i32 @fread(i32* %7, i32 1, i32 4, i32* %27)
%29 = load i32*, i32** %6
%30 = load i32, i32* @SEEK_END
%31 = call i32 @fseek(i32* %29, i32 0, i32 %30)
%32 = load i32*, i32** %6
%33 = call i32 @ftell(i32* %32)
store i32 %33, i32* %8
%34 = load i32*, i32** %6
%35 = load i32, i32* %7
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @fseek(i32* %34, i32 %35, i32 %36)
%38 = load i32, i32* %7
store i32 %38, i32* %9
br label %39
39: ; preds = %48, %22
%40 = load i32, i32* %9
%41 = load i32, i32* %8
%42 = sub nsw i32 %41, 4
%43 = icmp slt i32 %40, %42
br i1 %43, label %44, label %51
44: ; preds = %39
%45 = load i32*, i32** %6
%46 = call signext i8 @fgetc(i32* %45)
%47 = call i32 @putchar(i8 signext %46)
br label %48
48: ; preds = %44
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %39
51: ; preds = %39
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
store i32 0, i32* %3
br label %81
54: ; preds = %16, %2
%55 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %55, i32** %10
%56 = load i32*, i32** %10
%57 = icmp ne i32* %56, null
br i1 %57, label %58, label %80
58: ; preds = %54
%59 = call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %59, i32** %11
%60 = load i32*, i32** %11
%61 = call i32 @ftell(i32* %60)
store i32 %61, i32* %12
br label %62
62: ; preds = %69, %58
%63 = load i32*, i32** %10
%64 = call signext i8 @fgetc(i32* %63)
store i8 %64, i8* %13
%65 = sext i8 %64 to i32
%66 = load i8, i8* @EOF
%67 = sext i8 %66 to i32
%68 = icmp ne i32 %65, %67
br i1 %68, label %69, label %73
69: ; preds = %62
%70 = load i8, i8* %13
%71 = load i32*, i32** %11
%72 = call i32 @fputc(i8 signext %70, i32* %71)
br label %62
73: ; preds = %62
%74 = load i32*, i32** %11
%75 = call i32 @fwrite(i32* %12, i32 1, i32 4, i32* %74)
%76 = load i32*, i32** %11
%77 = call i32 @fclose(i32* %76)
%78 = load i32*, i32** %10
%79 = call i32 @fclose(i32* %78)
br label %80
80: ; preds = %73, %54
store i32 0, i32* %3
br label %81
81: ; preds = %80, %51
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str = [3 x i8] c"-s\00"
@.str.1 = [3 x i8] c"tt\00"
@.str.2 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c"tt.c\00"
@.str.4 = [3 x i8] c"ab\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %33
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %33
11: ; preds = %6
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @SEEK_END
%14 = tail call i32 @fseek(i32* %12, i32 -4, i32 %13)
%15 = bitcast i32* %3 to i8*
%16 = call i32 @fread(i32* %3, i32 1, i32 4, i32* %12)
%17 = load i32, i32* @SEEK_END
%18 = tail call i32 @fseek(i32* %12, i32 0, i32 %17)
%19 = tail call i32 @ftell(i32* %12)
%20 = load i32, i32* %3
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @fseek(i32* %12, i32 %20, i32 %21)
%23 = add i32 %19, -4
%24 = icmp slt i32 %20, %23
br i1 %24, label %25, label %31
25: ; preds = %11, %25
%26 = phi i32 [ %29, %25 ], [ %20, %11 ]
%27 = tail call signext i8 @fgetc(i32* %12)
%28 = tail call i32 @putchar(i8 signext %27)
%29 = add i32 %26, 1
%30 = icmp eq i32 %29, %23
br i1 %30, label %31, label %25
31: ; preds = %25, %11
%32 = tail call i32 @fclose(i32* %12)
br label %53
33: ; preds = %6, %2
%34 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %53, label %36
36: ; preds = %33
%37 = tail call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%38 = bitcast i32* %4 to i8*
%39 = tail call i32 @ftell(i32* %37)
store i32 %39, i32* %4
%40 = tail call signext i8 @fgetc(i32* %34)
%41 = load i8, i8* @EOF
%42 = icmp eq i8 %40, %41
br i1 %42, label %49, label %43
43: ; preds = %36, %43
%44 = phi i8 [ %46, %43 ], [ %40, %36 ]
%45 = tail call i32 @fputc(i8 signext %44, i32* %37)
%46 = tail call signext i8 @fgetc(i32* %34)
%47 = load i8, i8* @EOF
%48 = icmp eq i8 %46, %47
br i1 %48, label %49, label %43
49: ; preds = %43, %36
%50 = call i32 @fwrite(i32* %4, i32 1, i32 4, i32* %37)
%51 = tail call i32 @fclose(i32* %37)
%52 = tail call i32 @fclose(i32* %34)
br label %53
53: ; preds = %33, %49, %31
ret i32 0
}