#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int sscanf(char *, char *, int *, int *);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
void cgraph_load_dimensions(const char *fileName, int *nodes, int *edges) {
  FILE *f = fopen(fileName, "r");
  if (!f) {
    fprintf(stderr, "Could not open file %s\n", &(fileName[0]));
    exit(EXIT_FAILURE);
  }
  *nodes = -1;
  *edges = -1;
  char line[2048];
  while (fgets(line, 2048, f)) {
    if ((line[0] == 'p') || (line[0] == 'P')) {
      const char *p;
      if (((p = strstr(line, "edge")) != NULL)) {
        int shift = 7;
        if (p[5] == 's')
          ++shift;
        if (sscanf(line + shift, "%d %d", nodes, edges) != 2) {
          fprintf(stderr, "Error reading dimensions.\n");
          exit(EXIT_FAILURE);
        }
      }
    }
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<cgraph_load_dimensions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cf <cgraph_load_dimensions+0x5f>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
lea    -0x820(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x800,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12d5 <cgraph_load_dimensions+0x165>
movsbl -0x820(%rbp),%eax
cmp    $0x70,%eax
je     1222 <cgraph_load_dimensions+0xb2>
movsbl -0x820(%rbp),%eax
cmp    $0x50,%eax
jne    12d0 <cgraph_load_dimensions+0x160>
lea    -0x820(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x828(%rbp)
cmp    $0x0,%rax
je     12cb <cgraph_load_dimensions+0x15b>
movl   $0x7,-0x82c(%rbp)
mov    -0x828(%rbp),%rax
movsbl 0x5(%rax),%eax
cmp    $0x73,%eax
jne    1273 <cgraph_load_dimensions+0x103>
mov    -0x82c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x82c(%rbp)
lea    -0x820(%rbp),%rdi
movslq -0x82c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd8c(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     12c6 <cgraph_load_dimensions+0x156>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xd74(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12cb <cgraph_load_dimensions+0x15b>
jmp    12d0 <cgraph_load_dimensions+0x160>
jmp    11e3 <cgraph_load_dimensions+0x73>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgraph_load_dimensions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1272 <cgraph_load_dimensions+0x102>
mov    %rax,%rbx
movl   $0xffffffff,(%r15)
movl   $0xffffffff,(%r14)
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1258 <cgraph_load_dimensions+0xe8>
lea    0xe47(%rip),%r13
lea    0xe45(%rip),%rbp
jmp    11f5 <cgraph_load_dimensions+0x85>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1258 <cgraph_load_dimensions+0xe8>
movzbl (%rsp),%eax
and    $0xdf,%al
cmp    $0x50,%al
jne    11e0 <cgraph_load_dimensions+0x70>
mov    %r12,%rdi
mov    %r13,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11e0 <cgraph_load_dimensions+0x70>
xor    %ecx,%ecx
cmpb   $0x73,0x5(%rax)
sete   %cl
lea    (%rcx,%r12,1),%rdi
add    $0x7,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     11e0 <cgraph_load_dimensions+0x70>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    124a <cgraph_load_dimensions+0xda>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Could not open file %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"edge\00"
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [27 x i8] c"Error reading dimensions.\0A\00"
define void @cgraph_load_dimensions(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [2048 x i8]
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp ne i32* %13, null
br i1 %14, label %22, label %15
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %3
%23 = load i32*, i32** %5
store i32 -1, i32* %23
%24 = load i32*, i32** %6
store i32 -1, i32* %24
br label %25
25: ; preds = %69, %22
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%27 = load i32*, i32** %7
%28 = call i64 @fgets(i8* %26, i32 2048, i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %70
30: ; preds = %25
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 112
br i1 %34, label %40, label %35
35: ; preds = %30
%36 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 80
br i1 %39, label %40, label %69
40: ; preds = %35, %30
%41 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%42 = call i8* @strstr(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %42, i8** %9
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %68
44: ; preds = %40
store i32 7, i32* %10
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i64 5
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 115
br i1 %49, label %50, label %53
50: ; preds = %44
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %53
53: ; preds = %50, %44
%54 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i32*, i32** %5
%59 = load i32*, i32** %6
%60 = call i32 @sscanf(i8* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %58, i32* %59)
%61 = icmp ne i32 %60, 2
br i1 %61, label %62, label %67
62: ; preds = %53
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %53
br label %68
68: ; preds = %67, %40
br label %69
69: ; preds = %68, %35
br label %25
70: ; preds = %25
%71 = load i32*, i32** %7
%72 = call i32 @fclose(i32* %71)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Could not open file %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"edge\00"
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [27 x i8] c"Error reading dimensions.\0A\00"
define void @cgraph_load_dimensions(i8* %0, i32* %1, i32* %2) {
%4 = alloca [2048 x i8]
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %3
store i32 -1, i32* %1
store i32 -1, i32* %2
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%14 = call i64 @fgets(i8* %13, i32 2048, i32* %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %39, label %16
16: ; preds = %12, %36
%17 = load i8, i8* %13
%18 = and i8 %17, -33
%19 = icmp eq i8 %18, 80
br i1 %19, label %20, label %36
20: ; preds = %16
%21 = call i8* @strstr(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %36, label %23
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %21, i64 5
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 115
%27 = select i1 %26, i64 8, i64 7
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %27
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2)
%30 = icmp eq i32 %29, 2
br i1 %30, label %36, label %31
31: ; preds = %23
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %20, %23, %16
%37 = call i64 @fgets(i8* %13, i32 2048, i32* %5)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %16
39: ; preds = %36, %12
%40 = call i32 @fclose(i32* %5)
ret void
}