#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strdup(char *);
int strlen(char *);
int /*<<< orphan*/ terror(char *);
void readWorkloadFile(char *nomfich, char **workToDo, int *n) {
  FILE *fwork;
  char cadena[1024];
  *n = 0;
  fwork = fopen(nomfich, "rt");
  if (fwork == NULL)
    terror("opening Workload file");
  fgets(cadena, 1024, fwork);
  while (!feof(fwork)) {
    if (cadena[strlen(cadena) - 1] == '\n')
      cadena[strlen(cadena) - 1] = 0x00;
    workToDo[*n] = (char *)strdup(cadena);
    *n = *n + 1;
    fgets(cadena, 1024, fwork);
  }
  fclose(fwork);
}


x86 assembly (clang, -O0):
<readWorkloadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bc <readWorkloadFile+0x4c>
lea    0xe4c(%rip),%rdi
call   1070 <terror@plt>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ef <readWorkloadFile+0x7f>
jmp    1271 <readWorkloadFile+0x101>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    122a <readWorkloadFile+0xba>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
jmp    11d1 <readWorkloadFile+0x61>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readWorkloadFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
movl   $0x0,(%rdx)
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11aa <readWorkloadFile+0x3a>
lea    0xe5e(%rip),%rdi
call   1070 <terror@plt>
mov    %rsp,%rbx
jmp    11c5 <readWorkloadFile+0x55>
nop
mov    %rbx,%rdi
call   1090 <strdup@plt>
movslq (%r15),%rcx
mov    %rax,(%r14,%rcx,8)
lea    0x1(%rcx),%eax
mov    %eax,(%r15)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
mov    %r12,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1203 <readWorkloadFile+0x93>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11b0 <readWorkloadFile+0x40>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    11b0 <readWorkloadFile+0x40>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@.str.1 = [22 x i8] c"opening Workload file\00"
define void @readWorkloadFile(i8* %0, i8** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [1024 x i8]
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
%9 = load i32*, i32** %6
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @terror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %3
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%18 = load i32*, i32** %7
%19 = call i32 @fgets(i8* %17, i32 1024, i32* %18)
br label %20
20: ; preds = %40, %16
%21 = load i32*, i32** %7
%22 = call i32 @feof(i32* %21)
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %25, label %56
25: ; preds = %20
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 10
br i1 %33, label %34, label %40
34: ; preds = %25
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %34, %25
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%42 = call i64 @strdup(i8* %41)
%43 = inttoptr i64 %42 to i8*
%44 = load i8**, i8*** %5
%45 = load i32*, i32** %6
%46 = load i32, i32* %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %44, i64 %47
store i8* %43, i8** %48
%49 = load i32*, i32** %6
%50 = load i32, i32* %49
%51 = add nsw i32 %50, 1
%52 = load i32*, i32** %6
store i32 %51, i32* %52
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%54 = load i32*, i32** %7
%55 = call i32 @fgets(i8* %53, i32 1024, i32* %54)
br label %20
56: ; preds = %20
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@.str.1 = [22 x i8] c"opening Workload file\00"
define void @readWorkloadFile(i8* nocapture %0, i8** nocapture writeonly %1, i32* nocapture %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i32 0, i32* %2
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @terror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
%11 = call i32 @fgets(i8* %5, i32 1024, i32* %6)
%12 = call i32 @feof(i32* %6)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %36
14: ; preds = %10, %26
%15 = call i32 @strlen(i8* %5)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = call i32 @strlen(i8* %5)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %21, %14
%27 = call i64 @strdup(i8* %5)
%28 = inttoptr i64 %27 to i8*
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %1, i64 %30
store i8* %28, i8** %31
%32 = add nsw i32 %29, 1
store i32 %32, i32* %2
%33 = call i32 @fgets(i8* %5, i32 1024, i32* %6)
%34 = call i32 @feof(i32* %6)
%35 = icmp eq i32 %34, 0
br i1 %35, label %14, label %36
36: ; preds = %26, %10
%37 = call i32 @fclose(i32* %6)
ret void
}