#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int readFile(int typeOfRead, int taskID) {
  FILE *ifp;
  char *mode = "r";
  char outputFilename[] = "taskr.lst";
  char *p;
  char *string;
  char ID[6];
  char desc[255], comm[255], buffer[510];
  ifp = fopen("taskr.lst", mode);
  if (ifp == NULL) {
    fprintf(stderr, "Can't open task file, does it exist? \n");
    exit(1);
  }
  while (1) {
    if (fgets(buffer, 150, ifp) == NULL)
      break;
  }
  p = strtok(buffer, "%");
  if (p != NULL) {
    strcpy(ID, p);
    p = strtok(NULL, "%");
    if (p != NULL)
      strcpy(desc, p);
  }
  printf("\n Read value 1: %s; Read Value 2: %s; \n", ID, desc);
  return 0;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xe78(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe6f(%rip),%rax
mov    %rax,-0x22(%rbp)
mov    0xe6c(%rip),%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e0 <readFile+0x70>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11e5 <readFile+0x75>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x96,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1209 <readFile+0x99>
jmp    120e <readFile+0x9e>
jmp    11e5 <readFile+0x75>
lea    -0x440(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1271 <readFile+0x101>
lea    -0x3e(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdeb(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     126c <readFile+0xfc>
lea    -0x140(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1271 <readFile+0x101>
lea    -0x3e(%rbp),%rsi
lea    -0x140(%rbp),%rdx
lea    0xdb2(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r14
push   %rbx
sub    $0x318,%rsp
lea    0xe81(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     122e <readFile+0xbe>
mov    %rax,%rbx
lea    0x110(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x96,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11b0 <readFile+0x40>
lea    0xe67(%rip),%rsi
lea    0x110(%rsp),%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     120b <readFile+0x9b>
lea    0xa(%rsp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    0xe41(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     120b <readFile+0x9b>
lea    0x10(%rsp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    0xe23(%rip),%rdi
lea    0xa(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x318,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@__const.readFile.outputFilename = [10 x i8] c"taskr.lst\00"
@.str.1 = [10 x i8] c"taskr.lst\00"
@stderr = global i32 0
@.str.2 = [39 x i8] c"Can't open task file, does it exist? \0A\00"
@.str.3 = [2 x i8] c"%\00"
@.str.4 = [40 x i8] c"\0A Read value 1: %s; Read Value 2: %s; \0A\00"
define i32 @readFile(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca [10 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [6 x i8]
%11 = alloca [255 x i8]
%12 = alloca [255 x i8]
%13 = alloca [510 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
%14 = bitcast [10 x i8]* %7 to i8*
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32* %16, i32** %5
%17 = load i32*, i32** %5
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
br label %24
24: ; preds = %23, %30
%25 = getelementptr inbounds [510 x i8], [510 x i8]* %13, i64 0, i64 0
%26 = load i32*, i32** %5
%27 = call i32* @fgets(i8* %25, i32 150, i32* %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %24
br label %31
30: ; preds = %24
br label %24
31: ; preds = %29
%32 = getelementptr inbounds [510 x i8], [510 x i8]* %13, i64 0, i64 0
%33 = call i8* @strtok(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %48
36: ; preds = %31
%37 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%38 = load i8*, i8** %8
%39 = call i32 @strcpy(i8* %37, i8* %38)
%40 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %40, i8** %8
%41 = load i8*, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%45 = load i8*, i8** %8
%46 = call i32 @strcpy(i8* %44, i8* %45)
br label %47
47: ; preds = %43, %36
br label %48
48: ; preds = %47, %31
%49 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%50 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%51 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %49, i8* %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"taskr.lst\00"
@stderr = global i32 0
@.str.2 = [39 x i8] c"Can't open task file, does it exist? \0A\00"
@.str.3 = [2 x i8] c"%\00"
@.str.4 = [40 x i8] c"\0A Read value 1: %s; Read Value 2: %s; \0A\00"
define i32 @readFile(i32 %0, i32 %1) {
%3 = alloca [6 x i8]
%4 = alloca [255 x i8]
%5 = alloca [510 x i8]
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [510 x i8], [510 x i8]* %5, i64 0, i64 0
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2, %15
%16 = call i32* @fgets(i8* %8, i32 150, i32* %9)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %15
18: ; preds = %15
%19 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = call i32 @strcpy(i8* %6, i8* %19)
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = call i32 @strcpy(i8* %7, i8* %23)
br label %27
27: ; preds = %21, %25, %18
%28 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %6, i8* %7)
ret i32 0
}