#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *f1, *f2, *f3;
  int x;
  if (argc != 4) {
    printf("Neispravan poziv!\n");
    printf("Ispravan poziv: naziv ulazdat izlazdat1 izlazdat2\n");
    exit(1);
  }
  f1 = fopen(argv[1], "r");
  if (f1 == NULL) {
    printf("Datoteka %s ne postoji!\n", argv[1]);
    exit(2);
  }
  f2 = fopen(argv[2], "w");
  f3 = fopen(argv[3], "w");
  while (fscanf(f1, "%d", &x) == 1) {
    if (x % 2 == 0)
      fprintf(f2, "%d\n", x);
    else
      fprintf(f3, "%d\n", x);
  }
  fclose(f1);
  fclose(f2);
  fclose(f3);
  printf("Done");
  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)
je     11a6 <main+0x46>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe69(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    127a <main+0x11a>
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1262 <main+0x102>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xe0e(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1275 <main+0x115>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xdf6(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1219 <main+0xb9>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    1260 <main+0xf0>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1282 <main+0x112>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe6d(%rip),%rbp
mov    %rbp,%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    0x18(%rbx),%rdi
mov    %rbp,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe4e(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    1229 <main+0xb9>
lea    0xe38(%rip),%r12
lea    0xe2e(%rip),%r13
lea    0x4(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x4(%rsp),%edx
test   $0x1,%dl
mov    %rbx,%rdi
cmove  %r15,%rdi
mov    %r12,%rsi
call   1070 <fprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <fscanf@plt>
cmp    $0x1,%eax
je     1200 <main+0x90>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc2(%rip),%rdi
call   1030 <puts@plt>
lea    0xdc8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%rbx),%rsi
lea    0xd75(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Neispravan poziv!\0A\00"
@.str.1 = [51 x i8] c"Ispravan poziv: naziv ulazdat izlazdat1 izlazdat2\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [25 x i8] c"Datoteka %s ne postoji!\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.7 = [5 x i8] c"Done\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 ne i32 %10, 4
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 2)
unreachable
29: ; preds = %16
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %33, i32** %7
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %37, i32** %8
br label %38
38: ; preds = %54, %29
%39 = load i32*, i32** %6
%40 = call i32 @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %9)
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %55
42: ; preds = %38
%43 = load i32, i32* %9
%44 = srem i32 %43, 2
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i32*, i32** %7
%48 = load i32, i32* %9
%49 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %48)
br label %54
50: ; preds = %42
%51 = load i32*, i32** %8
%52 = load i32, i32* %9
%53 = call i32 @fprintf(i32* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %50, %46
br label %38
55: ; preds = %38
%56 = load i32*, i32** %6
%57 = call i32 @fclose(i32* %56)
%58 = load i32*, i32** %7
%59 = call i32 @fclose(i32* %58)
%60 = load i32*, i32** %8
%61 = call i32 @fclose(i32* %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [25 x i8] c"Datoteka %s ne postoji!\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.7 = [5 x i8] c"Done\00"
@str = [18 x i8] c"Neispravan poziv!\00"
@str.8 = [50 x i8] c"Ispravan poziv: naziv ulazdat izlazdat1 izlazdat2\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.8, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 2)
unreachable
19: ; preds = %10
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %36
28: ; preds = %19, %28
%29 = load i32, i32* %3
%30 = and i32 %29, 1
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i32* %22, i32* %25
%33 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%34 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%35 = icmp eq i32 %34, 1
br i1 %35, label %28, label %36
36: ; preds = %28, %19
%37 = call i32 @fclose(i32* %13)
%38 = call i32 @fclose(i32* %22)
%39 = call i32 @fclose(i32* %25)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}