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

/* Variables and functions */
int /*<<< orphan*/ assert(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int read_write_data(int /*<<< orphan*/ *, int /*<<< orphan*/ *, struct stat *);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int perform_action(const char *in_file, const char *out_file) {
  FILE *fin = NULL;
  FILE *fout = NULL;
  int status = 0;
  struct stat in_stat;
  assert(in_file);
  assert(out_file);
  if (0 != stat(in_file, &in_stat)) {
    fprintf(stderr, "Unable to locate in_file %s\n", in_file);
    return 1;
  }
  if (in_stat.st_size < 2) {
    fprintf(stderr, "Invalid input file %s. File size is less than 2\n",
            in_file);
    return 1;
  }
  fin = fopen(in_file, "rb");
  if (NULL == fin) {
    fprintf(stderr, "unable to open file %s for reading\n", in_file);
    return 1;
  }
  fout = fopen(out_file, "w");
  if (NULL == fout) {
    fprintf(stderr, "unable to open file %s for writing\n", out_file);
    fclose(fin);
    return 1;
  }
  status = read_write_data(fin, fout, &in_stat);
  if (0 == status) {
    fprintf(stdout, "Output written to %s\n\n", out_file);
  }
  fclose(fin);
  fclose(fout);
  return status;
}


x86 assembly (clang, -O0):
<perform_action>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11d9 <perform_action+0x79>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe38(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12eb <perform_action+0x18b>
cmpl   $0x2,-0x30(%rbp)
jge    1208 <perform_action+0xa8>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe26(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12eb <perform_action+0x18b>
mov    -0x10(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    124d <perform_action+0xed>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe15(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12eb <perform_action+0x18b>
mov    -0x18(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    129b <perform_action+0x13b>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdf6(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12eb <perform_action+0x18b>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <read_write_data@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmp    -0x2c(%rbp),%eax
jne    12d3 <perform_action+0x173>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdcd(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perform_action>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <assert@plt>
mov    %r14,%rdi
call   1050 <assert@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <stat@plt>
test   %rax,%rax
je     11a0 <perform_action+0x40>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
jmp    1234 <perform_action+0xd4>
cmpl   $0x1,(%rsp)
jg     11b8 <perform_action+0x58>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
jmp    1234 <perform_action+0xd4>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1224 <perform_action+0xc4>
mov    %rax,%r15
lea    0xe9f(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     124f <perform_action+0xef>
mov    %rax,%r12
mov    %rsp,%rdx
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <read_write_data@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1212 <perform_action+0xb2>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
jmp    1241 <perform_action+0xe1>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    123c <perform_action+0xdc>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"Unable to locate in_file %s\0A\00"
@.str.1 = [49 x i8] c"Invalid input file %s. File size is less than 2\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [36 x i8] c"unable to open file %s for reading\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [36 x i8] c"unable to open file %s for writing\0A\00"
@stdout = global i32 0
@.str.6 = [23 x i8] c"Output written to %s\0A\0A\00"
define i32 @perform_action(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i32 0, i32* %8
%10 = load i8*, i8** %4
%11 = call i32 @assert(i8* %10)
%12 = load i8*, i8** %5
%13 = call i32 @assert(i8* %12)
%14 = load i8*, i8** %4
%15 = call i64 @stat(i8* %14, %struct.stat* %9)
%16 = icmp ne i64 0, %15
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %4
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %65
21: ; preds = %2
%22 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%23 = load i32, i32* %22
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %4
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %65
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %6
%32 = load i32*, i32** %6
%33 = icmp eq i32* null, %32
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %4
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %36)
store i32 1, i32* %3
br label %65
38: ; preds = %29
%39 = load i8*, i8** %5
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %40, i32** %7
%41 = load i32*, i32** %7
%42 = icmp eq i32* null, %41
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %5
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
store i32 1, i32* %3
br label %65
49: ; preds = %38
%50 = load i32*, i32** %6
%51 = load i32*, i32** %7
%52 = call i32 @read_write_data(i32* %50, i32* %51, %struct.stat* %9)
store i32 %52, i32* %8
%53 = load i32, i32* %8
%54 = icmp eq i32 0, %53
br i1 %54, label %55, label %59
55: ; preds = %49
%56 = load i32, i32* @stdout
%57 = load i8*, i8** %5
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %55, %49
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
%62 = load i32*, i32** %7
%63 = call i32 @fclose(i32* %62)
%64 = load i32, i32* %8
store i32 %64, i32* %3
br label %65
65: ; preds = %59, %43, %34, %25, %17
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"Unable to locate in_file %s\0A\00"
@.str.1 = [49 x i8] c"Invalid input file %s. File size is less than 2\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [36 x i8] c"unable to open file %s for reading\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [36 x i8] c"unable to open file %s for writing\0A\00"
@stdout = global i32 0
@.str.6 = [23 x i8] c"Output written to %s\0A\0A\00"
define i32 @perform_action(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32 @assert(i8* %0)
%6 = tail call i32 @assert(i8* %1)
%7 = call i64 @stat(i8* %0, %struct.stat* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %41
12: ; preds = %2
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %41
19: ; preds = %12
%20 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %41
25: ; preds = %19
%26 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %1)
%31 = call i32 @fclose(i32* %20)
br label %41
32: ; preds = %25
%33 = call i32 @read_write_data(i32* %20, i32* %26, %struct.stat* %3)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* @stdout
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %1)
br label %38
38: ; preds = %35, %32
%39 = call i32 @fclose(i32* %20)
%40 = call i32 @fclose(i32* %26)
br label %41
41: ; preds = %38, %28, %22, %16, %9
%42 = phi i32 [ 1, %9 ], [ 1, %16 ], [ 1, %22 ], [ 1, %28 ], [ %33, %38 ]
ret i32 %42
}