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

/* Variables and functions */
int /*<<< orphan*/ begin_print(int /*<<< orphan*/ *);
int /*<<< orphan*/ check_instructions(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, char **argv) {
  char *path_to_file;
  struct timeval start, stop;
  int milsec;
  printf("Silvano's CNC - V. %s for %s\n", "0.0.1 alpha", "GNU/Linux");
  if (argc > 1) {
    path_to_file = argv[1];
  } else {
    char path[128];
    printf("Path to file: ");
    scanf("%s", path);
    path_to_file = path;
  }
  FILE *f = fopen(path_to_file, "r");
  if (f == NULL) {
    perror("ERROR");
    exit(errno);
  }
  printf("Checking file... ");
  check_instructions(f);
  printf("Valid file format.\n");
  printf("Begin.\n");
  gettimeofday(&start, NULL);
  begin_print(f);
  gettimeofday(&stop, NULL);
  milsec = (int)(1000 * (stop.tv_sec - start.tv_sec) +
                 (stop.tv_usec - start.tv_usec) / 1000);
  printf("Printing complete after %d milliseconds!", milsec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rdi
lea    0xe77(%rip),%rsi
lea    0xe7c(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11d0 <main+0x50>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11fc <main+0x7c>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1060 <scanf@plt>
lea    -0xb0(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
jne    123b <main+0xbb>
lea    0xe20(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xb8(%rbp),%rdi
call   10a0 <check_instructions@plt>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0xb8(%rbp),%rdi
call   1030 <begin_print@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x28(%rbp),%eax
sub    -0x20(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0xbc(%rbp)
mov    -0x24(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xbc(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe5b(%rip),%rdi
lea    0xe72(%rip),%rsi
lea    0xe77(%rip),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%ebp
jl     11c5 <main+0x35>
mov    0x8(%rbx),%rbx
jmp    11e7 <main+0x57>
lea    0x10(%rsp),%rbx
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe64(%rip),%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1299 <main+0x109>
mov    %rax,%rbx
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   10b0 <check_instructions@plt>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %rbx,%rdi
call   1040 <begin_print@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x10(%rsp),%eax
imul   $0x3e8,%eax,%eax
sub    0x14(%rsp),%ecx
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rsi
mov    %rsi,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rsi
add    %ecx,%esi
add    %eax,%esi
lea    0xdda(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xda8(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [30 x i8] c"Silvano's CNC - V. %s for %s\0A\00"
@.str.1 = [12 x i8] c"0.0.1 alpha\00"
@.str.2 = [10 x i8] c"GNU/Linux\00"
@.str.3 = [15 x i8] c"Path to file: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [6 x i8] c"ERROR\00"
@errno = global i32 0
@.str.7 = [18 x i8] c"Checking file... \00"
@.str.8 = [20 x i8] c"Valid file format.\0A\00"
@.str.9 = [8 x i8] c"Begin.\0A\00"
@.str.10 = [41 x i8] c"Printing complete after %d milliseconds!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca i32
%10 = alloca [128 x i8]
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
br label %24
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
store i8* %23, i8** %6
br label %24
24: ; preds = %19, %15
%25 = load i8*, i8** %6
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %26, i32** %11
%27 = load i32*, i32** %11
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%31 = load i32, i32* @errno
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %24
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%35 = load i32*, i32** %11
%36 = call i32 @check_instructions(i32* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
%39 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%40 = load i32*, i32** %11
%41 = call i32 @begin_print(i32* %40)
%42 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%46 = load i32, i32* %45
%47 = sub nsw i32 %44, %46
%48 = mul nsw i32 1000, %47
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%52 = load i32, i32* %51
%53 = sub nsw i32 %50, %52
%54 = sdiv i32 %53, 1000
%55 = add nsw i32 %48, %54
store i32 %55, i32* %9
%56 = load i32, i32* %9
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0), i32 %56)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [30 x i8] c"Silvano's CNC - V. %s for %s\0A\00"
@.str.1 = [12 x i8] c"0.0.1 alpha\00"
@.str.2 = [10 x i8] c"GNU/Linux\00"
@.str.3 = [15 x i8] c"Path to file: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [6 x i8] c"ERROR\00"
@errno = global i32 0
@.str.7 = [18 x i8] c"Checking file... \00"
@.str.10 = [41 x i8] c"Printing complete after %d milliseconds!\00"
@str = [19 x i8] c"Valid file format.\00"
@str.11 = [7 x i8] c"Begin.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca [128 x i8]
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
br label %17
13: ; preds = %2
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %14)
br label %17
17: ; preds = %13, %10
%18 = phi i8* [ %12, %10 ], [ %14, %13 ]
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%23 = load i32, i32* @errno
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %17
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%27 = call i32 @check_instructions(i32* %19)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.11, i64 0, i64 0))
%30 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%31 = call i32 @begin_print(i32* %19)
%32 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%36 = load i32, i32* %35
%37 = sub nsw i32 %34, %36
%38 = mul nsw i32 %37, 1000
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%42 = load i32, i32* %41
%43 = sub nsw i32 %40, %42
%44 = sdiv i32 %43, 1000
%45 = add nsw i32 %44, %38
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0), i32 %45)
ret i32 0
}