#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 */

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ system(char *);
void file_io(char *args[], char iname[], char outname[], int c) {
  c = -1;
  do {
    system("clear");
    if (!args[2]) {
      printf("Insert input file here:\n");
      fgets(iname, 50, stdin);
      iname[strlen(iname) - 1] = '\0';
    } else {
      iname = "";
    }
    printf("Insert output file here or leave blanc:\n");
    fgets(outname, 50, stdin);
  } while (strlen(outname) < 1);
  if (strlen(outname) > 2) {
    outname[strlen(outname) - 1] = '\0';
    c = 1;
  } else {
    c = 0;
  }
}


x86 assembly (clang, -O0):
<file_io>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    0xe9b(%rip),%rdi
call   1040 <system@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x10(%rax)
jne    11c2 <file_io+0x82>
lea    0xe86(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
mov    $0x32,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11cd <file_io+0x8d>
lea    0xe7e(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe4b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
mov    $0x32,%esi
call   1060 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jl     115e <file_io+0x1e>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jle    1241 <file_io+0x101>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x1c(%rbp)
jmp    1248 <file_io+0x108>
movl   $0x0,-0x1c(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_io>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r14
mov    0x2e8d(%rip),%r15
lea    0xebc(%rip),%r13
jmp    1197 <file_io+0x57>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
call   1030 <puts@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x32,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r12,%rbp
test   %eax,%eax
jg     11e1 <file_io+0xa1>
lea    0xe62(%rip),%rdi
call   1050 <system@plt>
cmpq   $0x0,0x10(%r14)
lea    0xe96(%rip),%r12
jne    1170 <file_io+0x30>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%edx
mov    %rbp,%rdi
mov    $0x32,%esi
call   1060 <fgets@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
mov    %rbp,%r12
jmp    1170 <file_io+0x30>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
jl     11fd <file_io+0xbd>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"clear\00"
@.str.1 = [25 x i8] c"Insert input file here:\0A\00"
@stdin = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [41 x i8] c"Insert output file here or leave blanc:\0A\00"
define void @file_io(i8** %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 -1, i32* %8
br label %9
9: ; preds = %32, %4
%10 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 2
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %26, label %15
15: ; preds = %9
%16 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %6
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 50, i32 %18)
%20 = load i8*, i8** %6
%21 = load i8*, i8** %6
%22 = call i32 @strlen(i8* %21)
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
store i8 0, i8* %25
br label %27
26: ; preds = %9
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %27
27: ; preds = %26, %15
%28 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%29 = load i8*, i8** %7
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %29, i32 50, i32 %30)
br label %32
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = call i32 @strlen(i8* %33)
%35 = icmp slt i32 %34, 1
br i1 %35, label %9, label %36
36: ; preds = %32
%37 = load i8*, i8** %7
%38 = call i32 @strlen(i8* %37)
%39 = icmp sgt i32 %38, 2
br i1 %39, label %40, label %47
40: ; preds = %36
%41 = load i8*, i8** %7
%42 = load i8*, i8** %7
%43 = call i32 @strlen(i8* %42)
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %41, i64 %45
store i8 0, i8* %46
store i32 1, i32* %8
br label %48
47: ; preds = %36
store i32 0, i32* %8
br label %48
48: ; preds = %47, %40
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"clear\00"
@stdin = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@str = [24 x i8] c"Insert input file here:\00"
@str.4 = [40 x i8] c"Insert output file here or leave blanc:\00"
define void @file_io(i8** nocapture %0, i8* %1, i8* %2, i32 %3) {
%5 = getelementptr inbounds i8*, i8** %0, i64 2
br label %6
6: ; preds = %19, %4
%7 = phi i8* [ %1, %4 ], [ %20, %19 ]
%8 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = tail call i32 @fgets(i8* %7, i32 50, i32 %13)
%15 = tail call i32 @strlen(i8* %7)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %7, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %6, %11
%20 = phi i8* [ %7, %11 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %6 ]
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.4, i64 0, i64 0))
%22 = load i32, i32* @stdin
%23 = tail call i32 @fgets(i8* %2, i32 50, i32 %22)
%24 = tail call i32 @strlen(i8* %2)
%25 = icmp slt i32 %24, 1
br i1 %25, label %6, label %26
26: ; preds = %19
%27 = tail call i32 @strlen(i8* %2)
%28 = icmp sgt i32 %27, 2
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = tail call i32 @strlen(i8* %2)
%31 = add nsw i32 %30, -1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %2, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %26, %29
ret void
}