#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*/ SEEK_SET;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fdopen(int, char *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
char *queryFileByLoc(int fd, int row, int col) {
  int curRow = 0;
  int curCol = 0;
  char *linePtr = NULL, *tokenPtr = NULL, *retPtr = NULL;
  size_t nSize = -1;
  FILE *file = NULL;
  if (lseek(fd, SEEK_SET, 0) == -1) {
    perror("lseek failed");
    exit(-1);
  }
  if ((file = fdopen(fd, "r")) == NULL) {
    perror("fdopen failed");
    exit(-1);
  }
  while (curRow <= row) {
    if (getline(&linePtr, &nSize, file) == -1) {
      if (feof(file)) {
        free(linePtr);
        return NULL;
      }
      perror("getline failed");
      exit(-1);
    }
    curRow++;
  }
  while (curCol <= col) {
    if ((tokenPtr = strtok((curCol == 0) ? linePtr : NULL, " ")) == NULL) {
      free(linePtr);
      return NULL;
    }
    curCol++;
  }
  if ((retPtr = (char *)calloc(1, sizeof(char) * strlen(tokenPtr))) == NULL) {
    perror("calloc failed");
    exit(-1);
  }
  strcpy(retPtr, tokenPtr);
  free(linePtr);
  if (retPtr[strlen(retPtr) - 1] == '\n') {
    retPtr[strlen(retPtr) - 1] = '\0';
  }
  return retPtr;
}


x86 assembly (clang, -O0):
<queryFileByLoc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0xffffffffffffffff,-0x40(%rbp)
ff
movq   $0x0,-0x48(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1229 <queryFileByLoc+0x79>
lea    0xde6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0xc(%rbp),%edi
lea    0xdda(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    125c <queryFileByLoc+0xac>
lea    0xdc2(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
jmp    1261 <queryFileByLoc+0xb1>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     12d4 <queryFileByLoc+0x124>
mov    -0x48(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10c0 <getline@plt>
cmp    $0xffffffff,%eax
jne    12c6 <queryFileByLoc+0x116>
mov    -0x48(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     12b0 <queryFileByLoc+0x100>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13f1 <queryFileByLoc+0x241>
lea    0xd66(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1261 <queryFileByLoc+0xb1>
jmp    12d9 <queryFileByLoc+0x129>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1349 <queryFileByLoc+0x199>
cmpl   $0x0,-0x1c(%rbp)
jne    12fc <queryFileByLoc+0x14c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    1307 <queryFileByLoc+0x157>
xor    %eax,%eax
mov    %rax,-0x50(%rbp)
jmp    1307 <queryFileByLoc+0x157>
mov    -0x50(%rbp),%rdi
lea    0xd1a(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    133b <queryFileByLoc+0x18b>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13f1 <queryFileByLoc+0x241>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12d9 <queryFileByLoc+0x129>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%esi
mov    $0x1,%edi
call   1070 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1388 <queryFileByLoc+0x1d8>
lea    0xcb5(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    13e9 <queryFileByLoc+0x239>
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<queryFileByLoc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
movq   $0x0,(%rsp)
movq   $0xffffffffffffffff,0x8(%rsp)
ff ff
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     12f4 <queryFileByLoc+0x144>
lea    0xe19(%rip),%rsi
mov    %ebp,%edi
call   1090 <fdopen@plt>
test   %rax,%rax
je     12fd <queryFileByLoc+0x14d>
test   %ebx,%ebx
js     123c <queryFileByLoc+0x8c>
mov    %rax,%rbp
add    $0x1,%ebx
mov    %rsp,%r15
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   10c0 <getline@plt>
cmp    $0xffffffff,%eax
je     12cc <queryFileByLoc+0x11c>
add    $0xffffffff,%ebx
jne    1220 <queryFileByLoc+0x70>
xor    %ebx,%ebx
test   %r14d,%r14d
js     127a <queryFileByLoc+0xca>
add    $0x1,%r14d
lea    0xdde(%rip),%rbp
xchg   %ax,%ax
test   %ebx,%ebx
jne    1260 <queryFileByLoc+0xb0>
mov    (%rsp),%rdi
jmp    1262 <queryFileByLoc+0xb2>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbp,%rsi
call   10b0 <strtok@plt>
test   %rax,%rax
je     12d9 <queryFileByLoc+0x129>
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    1250 <queryFileByLoc+0xa0>
mov    %rax,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x1,%edi
mov    %eax,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     1306 <queryFileByLoc+0x156>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    12e4 <queryFileByLoc+0x134>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
jmp    12e4 <queryFileByLoc+0x134>
mov    %rbp,%rdi
call   1080 <feof@plt>
test   %rax,%rax
je     130f <queryFileByLoc+0x15f>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd05(%rip),%rdi
jmp    1316 <queryFileByLoc+0x166>
lea    0xd0b(%rip),%rdi
jmp    1316 <queryFileByLoc+0x166>
lea    0xd21(%rip),%rdi
jmp    1316 <queryFileByLoc+0x166>
lea    0xd07(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [13 x i8] c"lseek failed\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"fdopen failed\00"
@.str.3 = [15 x i8] c"getline failed\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [14 x i8] c"calloc failed\00"
define i8* @queryFileByLoc(i32 %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
store i8* null, i8** %11
store i8* null, i8** %12
store i64 -1, i64* %13
store i32* null, i32** %14
%15 = load i32, i32* %5
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @lseek(i32 %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %3
%23 = load i32, i32* %5
%24 = call i32* @fdopen(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %14
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %22
br label %30
30: ; preds = %48, %29
%31 = load i32, i32* %8
%32 = load i32, i32* %6
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %51
34: ; preds = %30
%35 = load i32*, i32** %14
%36 = call i32 @getline(i8** %10, i64* %13, i32* %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %48
38: ; preds = %34
%39 = load i32*, i32** %14
%40 = call i64 @feof(i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i8*, i8** %10
%44 = call i32 @free(i8* %43)
store i8* null, i8** %4
br label %108
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %34
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %30
51: ; preds = %30
br label %52
52: ; preds = %69, %51
%53 = load i32, i32* %9
%54 = load i32, i32* %7
%55 = icmp sle i32 %53, %54
br i1 %55, label %56, label %72
56: ; preds = %52
%57 = load i32, i32* %9
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = load i8*, i8** %10
br label %62
61: ; preds = %56
br label %62
62: ; preds = %61, %59
%63 = phi i8* [ %60, %59 ], [ null, %61 ]
%64 = call i8* @strtok(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %64, i8** %11
%65 = icmp eq i8* %64, null
br i1 %65, label %66, label %69
66: ; preds = %62
%67 = load i8*, i8** %10
%68 = call i32 @free(i8* %67)
store i8* null, i8** %4
br label %108
69: ; preds = %62
%70 = load i32, i32* %9
%71 = add nsw i32 %70, 1
store i32 %71, i32* %9
br label %52
72: ; preds = %52
%73 = load i8*, i8** %11
%74 = call i32 @strlen(i8* %73)
%75 = sext i32 %74 to i64
%76 = mul i64 1, %75
%77 = trunc i64 %76 to i32
%78 = call i64 @calloc(i32 1, i32 %77)
%79 = inttoptr i64 %78 to i8*
store i8* %79, i8** %12
%80 = icmp eq i8* %79, null
br i1 %80, label %81, label %84
81: ; preds = %72
%82 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%83 = call i32 @exit(i32 -1)
unreachable
84: ; preds = %72
%85 = load i8*, i8** %12
%86 = load i8*, i8** %11
%87 = call i32 @strcpy(i8* %85, i8* %86)
%88 = load i8*, i8** %10
%89 = call i32 @free(i8* %88)
%90 = load i8*, i8** %12
%91 = load i8*, i8** %12
%92 = call i32 @strlen(i8* %91)
%93 = sub nsw i32 %92, 1
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %90, i64 %94
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = icmp eq i32 %97, 10
br i1 %98, label %99, label %106
99: ; preds = %84
%100 = load i8*, i8** %12
%101 = load i8*, i8** %12
%102 = call i32 @strlen(i8* %101)
%103 = sub nsw i32 %102, 1
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i8, i8* %100, i64 %104
store i8 0, i8* %105
br label %106
106: ; preds = %99, %84
%107 = load i8*, i8** %12
store i8* %107, i8** %4
br label %108
108: ; preds = %106, %66, %42
%109 = load i8*, i8** %4
ret i8* %109
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [13 x i8] c"lseek failed\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"fdopen failed\00"
@.str.3 = [15 x i8] c"getline failed\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [14 x i8] c"calloc failed\00"
define i8* @queryFileByLoc(i32 %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = bitcast i64* %5 to i8*
store i64 -1, i64* %5
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @lseek(i32 %0, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %3
%15 = tail call i32* @fdopen(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = icmp slt i32 %1, 0
br i1 %18, label %25, label %27
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %27
%23 = add nuw i32 %28, 1
%24 = icmp eq i32 %28, %1
br i1 %24, label %25, label %27
25: ; preds = %22, %17
%26 = icmp slt i32 %2, 0
br i1 %26, label %53, label %43
27: ; preds = %17, %22
%28 = phi i32 [ %23, %22 ], [ 0, %17 ]
%29 = call i32 @getline(i8** %4, i64* %5, i32* %15)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %22
31: ; preds = %27
%32 = call i64 @feof(i32* %15)
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i8*, i8** %4
%36 = call i32 @free(i8* %35)
br label %77
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %43
%41 = add nuw i32 %44, 1
%42 = icmp eq i32 %44, %2
br i1 %42, label %53, label %43
43: ; preds = %25, %40
%44 = phi i32 [ %41, %40 ], [ 0, %25 ]
%45 = icmp eq i32 %44, 0
%46 = load i8*, i8** %4
%47 = select i1 %45, i8* %46, i8* null
%48 = call i8* @strtok(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %40
50: ; preds = %43
%51 = load i8*, i8** %4
%52 = call i32 @free(i8* %51)
br label %77
53: ; preds = %40, %25
%54 = phi i8* [ null, %25 ], [ %48, %40 ]
%55 = call i32 @strlen(i8* %54)
%56 = call i64 @calloc(i32 1, i32 %55)
%57 = inttoptr i64 %56 to i8*
%58 = icmp eq i64 %56, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%61 = call i32 @exit(i32 -1)
unreachable
62: ; preds = %53
%63 = call i32 @strcpy(i8* %57, i8* %54)
%64 = load i8*, i8** %4
%65 = call i32 @free(i8* %64)
%66 = call i32 @strlen(i8* %57)
%67 = add nsw i32 %66, -1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %57, i64 %68
%70 = load i8, i8* %69
%71 = icmp eq i8 %70, 10
br i1 %71, label %72, label %77
72: ; preds = %62
%73 = call i32 @strlen(i8* %57)
%74 = add nsw i32 %73, -1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %57, i64 %75
store i8 0, i8* %76
br label %77
77: ; preds = %62, %72, %50, %34
%78 = phi i8* [ null, %34 ], [ null, %50 ], [ %57, %72 ], [ %57, %62 ]
ret i8* %78
}