#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*/ executable(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ is_port(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, char *);
int sscanf(char *, char *, int *, char **);
int /*<<< orphan*/ stderr;
int readFile(char *filePath) {
  FILE *fp;
  int res;
  fp = fopen(filePath, "r");
  char line[1024];
  while (fgets(line, 1024, fp)) {
    int curport;
    char *filepath;
    res = sscanf(line, "%i %ms", &curport, &filepath);
    memset(line, 0, 1024);
    if (res != 2) {
      fprintf(stderr, "ERROR: Ill-formed file\n");
      exit(1);
    }
    printf("port: %i Path: %s\n", curport, filepath);
    if (!is_port(curport)) {
      fprintf(stderr, "Not valid port number '%i'\n", curport);
      fprintf(stderr, "ERROR: Ill-formed file\n");
      exit(1);
    }
    if (!executable(filepath)) {
      fprintf(stderr, "ERROR: Cannot execute file\n");
      exit(1);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12ea <readFile+0x14a>
lea    -0x420(%rbp),%rdi
lea    0xe12(%rip),%rsi
lea    -0x424(%rbp),%rdx
lea    -0x430(%rbp),%rcx
call   10a0 <sscanf@plt>
mov    %eax,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
cmpl   $0x2,-0x14(%rbp)
je     1244 <readFile+0xa4>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x424(%rbp),%esi
mov    -0x430(%rbp),%rdx
lea    0xdc9(%rip),%rdi
call   1040 <printf@plt>
mov    -0x424(%rbp),%edi
call   1070 <is_port@plt>
cmp    $0x0,%eax
jne    12af <readFile+0x10f>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    -0x424(%rbp),%edx
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x430(%rbp),%rdi
call   1090 <executable@plt>
cmp    $0x0,%eax
jne    12e5 <readFile+0x145>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    11c3 <readFile+0x23>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0xe48(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     126e <readFile+0xce>
lea    0x10(%rsp),%rbx
lea    0x4(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0xe30(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xdf8(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   10a0 <sscanf@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
cmp    $0x2,%r14d
jne    128a <readFile+0xea>
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%rdx
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0x4(%rsp),%edi
call   1070 <is_port@plt>
test   %eax,%eax
je     1295 <readFile+0xf5>
mov    0x8(%rsp),%rdi
call   1090 <executable@plt>
test   %eax,%eax
je     12bb <readFile+0x11b>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1200 <readFile+0x60>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
jmp    12b2 <readFile+0x112>
mov    0x2d44(%rip),%rbx
mov    (%rbx),%edi
mov    0x4(%rsp),%edx
lea    0xd8b(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd50(%rip),%rsi
jmp    12cb <readFile+0x12b>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c"%i %ms\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"ERROR: Ill-formed file\0A\00"
@.str.3 = [19 x i8] c"port: %i Path: %s\0A\00"
@.str.4 = [28 x i8] c"Not valid port number '%i'\0A\00"
@.str.5 = [28 x i8] c"ERROR: Cannot execute file\0A\00"
define i32 @readFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
br label %10
10: ; preds = %48, %1
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = load i32*, i32** %3
%13 = call i64 @fgets(i8* %11, i32 1024, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %49
15: ; preds = %10
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8** %7)
store i32 %17, i32* %4
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 1024)
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 2
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %15
%27 = load i32, i32* %6
%28 = load i8*, i8** %7
%29 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %27, i8* %28)
%30 = load i32, i32* %6
%31 = call i32 @is_port(i32 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %40, label %33
33: ; preds = %26
%34 = load i32, i32* @stderr
%35 = load i32, i32* %6
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %26
%41 = load i8*, i8** %7
%42 = call i32 @executable(i8* %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %40
br label %10
49: ; preds = %10
%50 = load i32*, i32** %3
%51 = call i32 @fclose(i32* %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c"%i %ms\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"ERROR: Ill-formed file\0A\00"
@.str.3 = [19 x i8] c"port: %i Path: %s\0A\00"
@.str.4 = [28 x i8] c"Not valid port number '%i'\0A\00"
@.str.5 = [28 x i8] c"ERROR: Cannot execute file\0A\00"
define i32 @readFile(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i8*
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = call i64 @fgets(i8* %6, i32 1024, i32* %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %45, label %9
9: ; preds = %1
%10 = bitcast i32* %3 to i8*
%11 = bitcast i8** %4 to i8*
br label %12
12: ; preds = %9, %42
%13 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8** %4)
%14 = call i32 @memset(i8* %6, i32 0, i32 1024)
%15 = icmp eq i32 %13, 2
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = load i32, i32* %3
%22 = load i8*, i8** %4
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* %22)
%24 = load i32, i32* %3
%25 = call i32 @is_port(i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = load i32, i32* %3
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %20
%35 = load i8*, i8** %4
%36 = call i32 @executable(i8* %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = call i64 @fgets(i8* %6, i32 1024, i32* %5)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %12
45: ; preds = %42, %1
%46 = call i32 @fclose(i32* %5)
ret i32 0
}