#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*/ execv(char *, int /*<<< orphan*/ *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sleep(int);
int main() {
  FILE *input;
  char s[80];
  printf("Enter the full path to the file and press Enter:\n");
  do {
    scanf("%s", s);
    if ((input = fopen(s, "r")) == NULL)
      printf("Incorrect path, try another file:\n");
    else
      break;
  } while (1);
  int delay, id;
  while (!feof(input)) {
    fscanf(input, "%d %s\n", &delay, s);
    if ((id = fork()) != 0) {
      sleep(delay);
      execv(s, NULL);
    }
  }
  if (fclose(input)) {
    printf("An error occcured while closing the file.\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ea <main+0x5a>
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
jmp    11ef <main+0x5f>
jmp    1203 <main+0x73>
jmp    11f4 <main+0x64>
mov    $0x1,%al
test   $0x1,%al
jne    11ab <main+0x1b>
jmp    1203 <main+0x73>
jmp    1208 <main+0x78>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1226 <main+0x96>
jmp    126b <main+0xdb>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rcx
lea    0xe25(%rip),%rsi
lea    -0x64(%rbp),%rdx
call   1050 <fscanf@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x68(%rbp)
cmp    $0x0,%eax
je     1266 <main+0xd6>
mov    -0x64(%rbp),%edi
call   1090 <sleep@plt>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <execv@plt>
jmp    1208 <main+0x78>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1296 <main+0x106>
lea    0xddc(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129d <main+0x10d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x60,%rsp
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
lea    0xe50(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe3f(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1216 <main+0x86>
lea    0xe8c(%rip),%r14
lea    0xe1e(%rip),%r15
lea    0x10(%rsp),%r12
lea    0xe15(%rip),%r13
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f0 <main+0x60>
mov    %rax,%rbx
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1242 <main+0xb2>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     129d <main+0x10d>
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    129f <main+0x10f>
lea    0xdbc(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    126c <main+0xdc>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1222 <main+0x92>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1050 <fscanf@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1260 <main+0xd0>
mov    0xc(%rsp),%edi
call   1090 <sleep@plt>
mov    %r12,%rdi
xor    %esi,%esi
call   10a0 <execv@plt>
jmp    1260 <main+0xd0>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Enter the full path to the file and press Enter:\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [35 x i8] c"Incorrect path, try another file:\0A\00"
@.str.4 = [7 x i8] c"%d %s\0A\00"
@.str.5 = [43 x i8] c"An error occcured while closing the file.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [80 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %17, %0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %16
15: ; preds = %7
br label %18
16: ; preds = %13
br label %17
17: ; preds = %16
br i1 true, label %7, label %18
18: ; preds = %17, %15
br label %19
19: ; preds = %35, %18
%20 = load i32*, i32** %2
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %36
24: ; preds = %19
%25 = load i32*, i32** %2
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%27 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %4, i8* %26)
%28 = call i32 (...) @fork()
store i32 %28, i32* %5
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %24
%31 = load i32, i32* %4
%32 = call i32 @sleep(i32 %31)
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%34 = call i32 @execv(i8* %33, i32* null)
br label %35
35: ; preds = %30, %24
br label %19
36: ; preds = %19
%37 = load i32*, i32** %2
%38 = call i64 @fclose(i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %43
42: ; preds = %36
store i32 0, i32* %1
br label %43
43: ; preds = %42, %40
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [7 x i8] c"%d %s\0A\00"
@str = [49 x i8] c"Enter the full path to the file and press Enter:\00"
@str.6 = [42 x i8] c"An error occcured while closing the file.\00"
@str.7 = [34 x i8] c"Incorrect path, try another file:\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %0, %8
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.7, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%11 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %8, label %13
13: ; preds = %8, %0
%14 = phi i32* [ %6, %0 ], [ %11, %8 ]
%15 = bitcast i32* %2 to i8*
%16 = call i32 @feof(i32* %14)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %13, %26
%19 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %2, i8* %3)
%20 = call i32 (...) @fork()
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* %2
%24 = call i32 @sleep(i32 %23)
%25 = call i32 @execv(i8* %3, i32* null)
br label %26
26: ; preds = %22, %18
%27 = call i32 @feof(i32* %14)
%28 = icmp eq i32 %27, 0
br i1 %28, label %18, label %29
29: ; preds = %26, %13
%30 = call i64 @fclose(i32* %14)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.6, i64 0, i64 0))
br label %34
34: ; preds = %29, %32
%35 = phi i32 [ 1, %32 ], [ 0, %29 ]
ret i32 %35
}