#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 {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int asprintf(char **, char *, char *, char *);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char **, int);
int /*<<< orphan*/ write(int, ...);
int main(int argc, char **argv) {
  int wfd, n, rfd, sz, rc = 0;
  struct stat sbuf;
  char buf[32768];
  char *fnm;
  if (argc < 3) {
    printf("%s [debugfs mount path] [ept_dict saved file]\n", argv[0]);
    exit(0);
  }
  rfd = open(argv[2], O_RDONLY);
  if (rfd < 0) {
    printf("Error opening rfd: %d\n", errno);
    exit(0);
  }
  rc = asprintf(&fnm, "%s/%s", argv[1], "ept_dict");
  if (rc < 0) {
    printf("Error allocating string: %d\n", errno);
    exit(0);
  }
  wfd = open(fnm, O_RDWR);
  if (wfd < 0) {
    printf("Error opening wfd: %d\n", errno);
    exit(0);
  }
  rc = fstat(rfd, &sbuf);
  if (rc < 0) {
    printf("Error fstat: %d\n", rc);
    exit(0);
  }
  sz = (int)sbuf.st_size;
  write(wfd, &sz, sizeof(int));
  while ((n = read(rfd, &buf, sizeof(buf)))) {
    write(wfd, buf, n);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11b6 <main+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11f7 <main+0x87>
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    -0x8038(%rbp),%rdi
lea    0xe39(%rip),%rsi
lea    0xe38(%rip),%rcx
call   1060 <asprintf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1244 <main+0xd4>
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x8038(%rbp),%rdi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1284 <main+0x114>
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1090 <fstat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12b5 <main+0x145>
mov    -0x24(%rbp),%esi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
lea    -0x8030(%rbp),%rsi
mov    $0x8000,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1308 <main+0x198>
mov    -0x14(%rbp),%edi
lea    -0x8030(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    12cf <main+0x15f>
mov    -0x4(%rbp),%eax
add    $0x8040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x8020,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    1260 <main+0xf0>
mov    0x10(%rbx),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1278 <main+0x108>
mov    %eax,%r14d
mov    0x8(%rbx),%rdx
lea    0xe97(%rip),%rsi
lea    0xe96(%rip),%rcx
lea    0x10(%rsp),%rdi
call   1060 <asprintf@plt>
test   %eax,%eax
js     128a <main+0x11a>
mov    0x10(%rsp),%rdi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     129c <main+0x12c>
mov    %eax,%ebp
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
call   1090 <fstat@plt>
test   %eax,%eax
js     12ae <main+0x13e>
mov    0x18(%rsp),%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <write@plt>
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0x8000,%edx
call   1050 <read@plt>
test   %eax,%eax
je     1252 <main+0xe2>
lea    0x20(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x8000,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    1230 <main+0xc0>
xor    %eax,%eax
add    $0x8020,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xd96(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
lea    0xda7(%rip),%rdi
jmp    12b7 <main+0x147>
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
lea    0xdbb(%rip),%rdi
jmp    12b7 <main+0x147>
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
lea    0xdc6(%rip),%rdi
jmp    12b7 <main+0x147>
lea    0xdd4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [47 x i8] c"%s [debugfs mount path] [ept_dict saved file]\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"Error opening rfd: %d\0A\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [9 x i8] c"ept_dict\00"
@.str.4 = [29 x i8] c"Error allocating string: %d\0A\00"
@O_RDWR = global i32 0
@.str.5 = [23 x i8] c"Error opening wfd: %d\0A\00"
@.str.6 = [17 x i8] c"Error fstat: %d\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
%10 = alloca i32
%11 = alloca %struct.stat
%12 = alloca [32768 x i8]
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %25, i32 %26)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %22
%31 = load i32, i32* @errno
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %22
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @asprintf(i8** %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %34
%42 = load i32, i32* @errno
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %34
%46 = load i8*, i8** %13
%47 = load i32, i32* @O_RDWR
%48 = call i32 @open(i8* %46, i32 %47)
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %45
%52 = load i32, i32* @errno
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %45
%56 = load i32, i32* %8
%57 = call i32 @fstat(i32 %56, %struct.stat* %11)
store i32 %57, i32* %10
%58 = load i32, i32* %10
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %55
%61 = load i32, i32* %10
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %61)
%63 = call i32 @exit(i32 0)
unreachable
64: ; preds = %55
%65 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%66 = load i64, i64* %65
%67 = trunc i64 %66 to i32
store i32 %67, i32* %9
%68 = load i32, i32* %6
%69 = call i32 (i32, ...) @write(i32 %68, i32* %9, i64 4)
br label %70
70: ; preds = %75, %64
%71 = load i32, i32* %8
%72 = bitcast [32768 x i8]* %12 to i8**
%73 = call i32 @read(i32 %71, i8** %72, i32 32768)
store i32 %73, i32* %7
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %80
75: ; preds = %70
%76 = load i32, i32* %6
%77 = getelementptr inbounds [32768 x i8], [32768 x i8]* %12, i64 0, i64 0
%78 = load i32, i32* %7
%79 = call i32 (i32, ...) @write(i32 %76, i8* %77, i32 %78)
br label %70
80: ; preds = %70
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [47 x i8] c"%s [debugfs mount path] [ept_dict saved file]\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"Error opening rfd: %d\0A\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [9 x i8] c"ept_dict\00"
@.str.4 = [29 x i8] c"Error allocating string: %d\0A\00"
@O_RDWR = global i32 0
@.str.5 = [23 x i8] c"Error opening wfd: %d\0A\00"
@.str.6 = [17 x i8] c"Error fstat: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.stat
%5 = alloca [32768 x i8]
%6 = alloca i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.stat* %4 to i8*
%9 = getelementptr inbounds [32768 x i8], [32768 x i8]* %5, i64 0, i64 0
%10 = bitcast i8** %6 to i8*
%11 = icmp slt i32 %0, 3
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* %18, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* @errno
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = tail call i32 @exit(i32 0)
unreachable
26: ; preds = %16
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* @errno
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %26
%36 = load i8*, i8** %6
%37 = load i32, i32* @O_RDWR
%38 = call i32 @open(i8* %36, i32 %37)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = load i32, i32* @errno
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %35
%45 = call i32 @fstat(i32 %20, %struct.stat* %4)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %44
%51 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%52 = load i64, i64* %51
%53 = trunc i64 %52 to i32
store i32 %53, i32* %3
%54 = call i32 (i32, ...) @write(i32 %38, i32* %3, i64 4)
%55 = bitcast [32768 x i8]* %5 to i8**
%56 = call i32 @read(i32 %20, i8** %55, i32 32768)
%57 = icmp eq i32 %56, 0
br i1 %57, label %63, label %58
58: ; preds = %50, %58
%59 = phi i32 [ %61, %58 ], [ %56, %50 ]
%60 = call i32 (i32, ...) @write(i32 %38, i8* %9, i32 %59)
%61 = call i32 @read(i32 %20, i8** %55, i32 32768)
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %58
63: ; preds = %58, %50
ret i32 0
}