#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strncmp(char *, char *, int);
char *strtok(char *, char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int parseTSPDimensionality(FILE *fp) {
  bool dimensionRecord = false;
  char buffer[127];
  int dimen = 0;
  while (fgets(buffer, 127, fp) != NULL) {
    char *str1, *str2, *token, *subtoken;
    char *delimiter = "\n";
    char *subdelim = ": ";
    int i;
    for (i = 0, str1 = buffer;; i++, str1 = NULL) {
      token = strtok(str1, delimiter);
      if (token == NULL) {
        break;
      }
      for (str2 = token;; str2 = NULL) {
        subtoken = strtok(str2, subdelim);
        if (subtoken == NULL) {
          break;
        }
        if (dimensionRecord == true) {
          int dim = (int)strtol(subtoken, NULL, 0);
          printf(" --> %d\n", dim);
          return dim;
        }
        if (strncmp(subtoken, "DIMEN", 5) == 0) {
          dimensionRecord = true;
          printf(" --> %s\n", token);
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parseTSPDimensionality>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xa4(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x7f,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12eb <parseTSPDimensionality+0x19b>
lea    0xe74(%rip),%rax
mov    %rax,-0xd0(%rbp)
lea    0xe5c(%rip),%rax
mov    %rax,-0xd8(%rbp)
movl   $0x0,-0xdc(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0xb0(%rbp),%rdi
mov    -0xd0(%rbp),%rsi
call   1070 <strtok@plt>
mov    %rax,-0xc0(%rbp)
cmpq   $0x0,-0xc0(%rbp)
jne    11f0 <parseTSPDimensionality+0xa0>
jmp    12e6 <parseTSPDimensionality+0x196>
mov    -0xc0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
call   1070 <strtok@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
jne    122b <parseTSPDimensionality+0xdb>
jmp    12c2 <parseTSPDimensionality+0x172>
cmpl   $0x1,-0x14(%rbp)
jne    126f <parseTSPDimensionality+0x11f>
mov    -0xc8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0xe0(%rbp)
mov    -0xe0(%rbp),%esi
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xe0(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12f2 <parseTSPDimensionality+0x1a2>
mov    -0xc8(%rbp),%rdi
lea    0xd8f(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12ad <parseTSPDimensionality+0x15d>
movl   $0x1,-0x14(%rbp)
mov    -0xc0(%rbp),%rsi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b2 <parseTSPDimensionality+0x162>
movq   $0x0,-0xb8(%rbp)
jmp    11fe <parseTSPDimensionality+0xae>
jmp    12c7 <parseTSPDimensionality+0x177>
mov    -0xdc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xdc(%rbp)
movq   $0x0,-0xb0(%rbp)
jmp    11c3 <parseTSPDimensionality+0x73>
jmp    1170 <parseTSPDimensionality+0x20>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseTSPDimensionality>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rdi,%rdx
lea    0x10(%rsp),%rdi
mov    $0x7f,%esi
mov    %rdx,0x8(%rsp)
call   1050 <fgets@plt>
test   %rax,%rax
je     1237 <parseTSPDimensionality+0xe7>
lea    0xe82(%rip),%rsi
lea    0x10(%rsp),%rbx
lea    0xe6c(%rip),%rbp
lea    0xe71(%rip),%r13
lea    0xe70(%rip),%r12
xor    %r14d,%r14d
mov    %rbx,%rdi
jmp    11b9 <parseTSPDimensionality+0x69>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
lea    0xe51(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,%r15
test   %rax,%rax
je     1210 <parseTSPDimensionality+0xc0>
mov    %r15,%rdi
jmp    11d2 <parseTSPDimensionality+0x82>
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     11b0 <parseTSPDimensionality+0x60>
mov    %rax,%rdi
cmp    $0x1,%r14d
je     123b <parseTSPDimensionality+0xeb>
mov    %r13,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11d0 <parseTSPDimensionality+0x80>
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
jmp    11d0 <parseTSPDimensionality+0x80>
nop
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x7f,%esi
mov    0x8(%rsp),%rdx
call   1050 <fgets@plt>
test   %rax,%rax
lea    0xdd9(%rip),%rsi
jne    11a5 <parseTSPDimensionality+0x55>
xor    %ebx,%ebx
jmp    1257 <parseTSPDimensionality+0x107>
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,%rbx
lea    0xdb5(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [3 x i8] c": \00"
@.str.2 = [9 x i8] c" --> %d\0A\00"
@.str.3 = [6 x i8] c"DIMEN\00"
@.str.4 = [9 x i8] c" --> %s\0A\00"
define i32 @parseTSPDimensionality(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [127 x i8]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %4
store i32 0, i32* %6
br label %15
15: ; preds = %61, %1
%16 = getelementptr inbounds [127 x i8], [127 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i32* @fgets(i8* %16, i32 127, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %62
20: ; preds = %15
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %11
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %12
store i32 0, i32* %13
%21 = getelementptr inbounds [127 x i8], [127 x i8]* %5, i64 0, i64 0
store i8* %21, i8** %7
br label %22
22: ; preds = %58, %20
%23 = load i8*, i8** %7
%24 = load i8*, i8** %11
%25 = call i8* @strtok(i8* %23, i8* %24)
store i8* %25, i8** %9
%26 = load i8*, i8** %9
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %22
br label %61
29: ; preds = %22
%30 = load i8*, i8** %9
store i8* %30, i8** %8
br label %31
31: ; preds = %56, %29
%32 = load i8*, i8** %8
%33 = load i8*, i8** %12
%34 = call i8* @strtok(i8* %32, i8* %33)
store i8* %34, i8** %10
%35 = load i8*, i8** %10
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %38
37: ; preds = %31
br label %57
38: ; preds = %31
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i8*, i8** %10
%43 = call i64 @strtol(i8* %42, i32* null, i32 0)
%44 = trunc i64 %43 to i32
store i32 %44, i32* %14
%45 = load i32, i32* %14
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %14
store i32 %47, i32* %2
br label %63
48: ; preds = %38
%49 = load i8*, i8** %10
%50 = call i64 @strncmp(i8* %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
store i32 1, i32* %4
%53 = load i8*, i8** %9
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52, %48
br label %56
56: ; preds = %55
store i8* null, i8** %8
br label %31
57: ; preds = %37
br label %58
58: ; preds = %57
%59 = load i32, i32* %13
%60 = add nsw i32 %59, 1
store i32 %60, i32* %13
store i8* null, i8** %7
br label %22
61: ; preds = %28
br label %15
62: ; preds = %15
store i32 0, i32* %2
br label %63
63: ; preds = %62, %41
%64 = load i32, i32* %2
ret i32 %64
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [3 x i8] c": \00"
@.str.2 = [9 x i8] c" --> %d\0A\00"
@.str.3 = [6 x i8] c"DIMEN\00"
@.str.4 = [9 x i8] c" --> %s\0A\00"
define i32 @parseTSPDimensionality(i32* nocapture %0) {
%2 = alloca [127 x i8]
%3 = getelementptr inbounds [127 x i8], [127 x i8]* %2, i64 0, i64 0
%4 = call i32* @fgets(i8* %3, i32 127, i32* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %40, label %6
6: ; preds = %1, %36
%7 = phi i32 [ %37, %36 ], [ 0, %1 ]
%8 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %36, label %14
10: ; preds = %32, %14
%11 = phi i32 [ %16, %14 ], [ %33, %32 ]
%12 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %36, label %14
14: ; preds = %6, %10
%15 = phi i8* [ %12, %10 ], [ %8, %6 ]
%16 = phi i32 [ %11, %10 ], [ %7, %6 ]
%17 = call i8* @strtok(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %10, label %19
19: ; preds = %14, %32
%20 = phi i8* [ %34, %32 ], [ %17, %14 ]
%21 = phi i32 [ %33, %32 ], [ %16, %14 ]
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = call i64 @strtol(i8* nocapture %20, i32* null, i32 0)
%25 = trunc i64 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %40
27: ; preds = %19
%28 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %15)
br label %32
32: ; preds = %27, %30
%33 = phi i32 [ 1, %30 ], [ %21, %27 ]
%34 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i8* %34, null
br i1 %35, label %10, label %19
36: ; preds = %10, %6
%37 = phi i32 [ %7, %6 ], [ %11, %10 ]
%38 = call i32* @fgets(i8* %3, i32 127, i32* %0)
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %6
40: ; preds = %36, %1, %23
%41 = phi i32 [ %25, %23 ], [ 0, %1 ], [ 0, %36 ]
ret i32 %41
}