#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ isdigit(int);
int /*<<< orphan*/ isspace(int);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *);
void find_version(const char *file, int *maj, int *min) {
  char line[256], *str, *s;
  FILE *f = fopen(file, "r");
  *maj = *min = 0;
  if (f) {
    for (;;) {
      s = str = fgets(line, sizeof(line), f);
      if (s) {
        while (*s) {
          if (!isspace((int)*s))
            goto outta_here;
          s++;
        }
      } else {
        break;
      }
    }
  outta_here:
    if (str) {
      while (*str && !isdigit((int)*str)) {
        ++str;
      }
      if (*str) {
        sscanf(str, "%d.%d", maj, min);
      }
    }
    fclose(f);
  }
}


x86 assembly (clang, -O0):
<find_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x138(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x0,-0x138(%rbp)
je     12f7 <find_version+0x197>
jmp    11b5 <find_version+0x55>
lea    -0x120(%rbp),%rdi
mov    -0x138(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    %rax,-0x128(%rbp)
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
je     1237 <find_version+0xd7>
jmp    11ee <find_version+0x8e>
mov    -0x130(%rbp),%rax
cmpb   $0x0,(%rax)
je     1232 <find_version+0xd2>
mov    -0x130(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%eax
jne    121b <find_version+0xbb>
jmp    1246 <find_version+0xe6>
mov    -0x130(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x130(%rbp)
jmp    11ee <find_version+0x8e>
jmp    123c <find_version+0xdc>
jmp    1241 <find_version+0xe1>
jmp    11b5 <find_version+0x55>
jmp    1246 <find_version+0xe6>
cmpq   $0x0,-0x128(%rbp)
je     12eb <find_version+0x18b>
jmp    1259 <find_version+0xf9>
mov    -0x128(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x139(%rbp)
je     1291 <find_version+0x131>
mov    -0x128(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x139(%rbp)
mov    -0x139(%rbp),%al
test   $0x1,%al
jne    12a4 <find_version+0x144>
jmp    12bb <find_version+0x15b>
mov    -0x128(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x128(%rbp)
jmp    1259 <find_version+0xf9>
mov    -0x128(%rbp),%rax
cmpb   $0x0,(%rax)
je     12e6 <find_version+0x186>
mov    -0x128(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd21(%rip),%rsi
call   1070 <sscanf@plt>
jmp    12eb <find_version+0x18b>
mov    -0x138(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_version>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
movl   $0x0,(%r14)
movl   $0x0,(%r15)
test   %rax,%rax
je     1252 <find_version+0x102>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     124a <find_version+0xfa>
mov    %rax,%rbx
jmp    11cc <find_version+0x7c>
nopl   0x0(%rax,%rax,1)
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
mov    %rax,%rbx
test   %rax,%rax
je     124a <find_version+0xfa>
movsbl (%rbx),%ebp
test   %ebp,%ebp
je     11b0 <find_version+0x60>
lea    0x1(%rbx),%r13
mov    %ebp,%eax
nopl   0x0(%rax)
movsbl %al,%edi
call   1040 <isspace@plt>
test   %eax,%eax
je     11fb <find_version+0xab>
movzbl 0x0(%r13),%eax
add    $0x1,%r13
test   %al,%al
jne    11e0 <find_version+0x90>
jmp    11b0 <find_version+0x60>
add    $0xffffffc6,%ebp
cmp    $0xfffffff5,%ebp
ja     122f <find_version+0xdf>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %eax,%eax
je     1224 <find_version+0xd4>
lea    -0x3a(%rax),%ecx
cmp    $0xfffffff6,%ecx
jb     1210 <find_version+0xc0>
test   %al,%al
sete   %al
test   %al,%al
je     1235 <find_version+0xe5>
jmp    124a <find_version+0xfa>
xor    %eax,%eax
test   %al,%al
jne    124a <find_version+0xfa>
lea    0xdc6(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"%d.%d\00"
define void @find_version(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [256 x i8]
%8 = alloca 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** %10
%13 = load i32*, i32** %6
store i32 0, i32* %13
%14 = load i32*, i32** %5
store i32 0, i32* %14
%15 = load i32*, i32** %10
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %77
17: ; preds = %3
br label %18
18: ; preds = %41, %17
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = load i32*, i32** %10
%21 = call i8* @fgets(i8* %19, i32 256, i32* %20)
store i8* %21, i8** %8
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %40
24: ; preds = %18
br label %25
25: ; preds = %36, %24
%26 = load i8*, i8** %9
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %25
%30 = load i8*, i8** %9
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = call i32 @isspace(i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %29
br label %43
36: ; preds = %29
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %9
br label %25
39: ; preds = %25
br label %41
40: ; preds = %18
br label %42
41: ; preds = %39
br label %18
42: ; preds = %40
br label %43
43: ; preds = %42, %35
%44 = load i8*, i8** %8
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %74
46: ; preds = %43
br label %47
47: ; preds = %61, %46
%48 = load i8*, i8** %8
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %59
52: ; preds = %47
%53 = load i8*, i8** %8
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = call i32 @isdigit(i32 %55)
%57 = icmp ne i32 %56, 0
%58 = xor i1 %57, true
br label %59
59: ; preds = %52, %47
%60 = phi i1 [ false, %47 ], [ %58, %52 ]
br i1 %60, label %61, label %64
61: ; preds = %59
%62 = load i8*, i8** %8
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %8
br label %47
64: ; preds = %59
%65 = load i8*, i8** %8
%66 = load i8, i8* %65
%67 = icmp ne i8 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %64
%69 = load i8*, i8** %8
%70 = load i32*, i32** %5
%71 = load i32*, i32** %6
%72 = call i32 @sscanf(i8* %69, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %70, i32* %71)
br label %73
73: ; preds = %68, %64
br label %74
74: ; preds = %73, %43
%75 = load i32*, i32** %10
%76 = call i32 @fclose(i32* %75)
br label %77
77: ; preds = %74, %3
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"%d.%d\00"
define void @find_version(i8* nocapture %0, i32* %1, i32* %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
store i32 0, i32* %1
%7 = icmp eq i32* %6, null
br i1 %7, label %50, label %8
8: ; preds = %3
%9 = call i8* @fgets(i8* %5, i32 256, i32* %6)
%10 = icmp eq i8* %9, null
br i1 %10, label %48, label %14
11: ; preds = %18, %14
%12 = call i8* @fgets(i8* %5, i32 256, i32* %6)
%13 = icmp eq i8* %12, null
br i1 %13, label %48, label %14
14: ; preds = %8, %11
%15 = phi i8* [ %12, %11 ], [ %9, %8 ]
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %11, label %21
18: ; preds = %21
%19 = load i8, i8* %27
%20 = icmp eq i8 %19, 0
br i1 %20, label %11, label %21
21: ; preds = %14, %18
%22 = phi i8 [ %19, %18 ], [ %16, %14 ]
%23 = phi i8* [ %27, %18 ], [ %15, %14 ]
%24 = sext i8 %22 to i32
%25 = call i32 @isspace(i32 %24)
%26 = icmp eq i32 %25, 0
%27 = getelementptr inbounds i8, i8* %23, i64 1
br i1 %26, label %28, label %18
28: ; preds = %21
%29 = sext i8 %16 to i32
%30 = add nsw i32 %29, -58
%31 = icmp ult i32 %30, -10
br i1 %31, label %32, label %43
32: ; preds = %28, %32
%33 = phi i8* [ %34, %32 ], [ %15, %28 ]
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = icmp ne i8 %35, 0
%37 = sext i8 %35 to i32
%38 = add nsw i32 %37, -58
%39 = icmp ult i32 %38, -10
%40 = select i1 %36, i1 %39, i1 false
br i1 %40, label %32, label %41
41: ; preds = %32
%42 = icmp eq i8 %35, 0
br label %43
43: ; preds = %41, %28
%44 = phi i1 [ %42, %41 ], [ false, %28 ]
%45 = phi i8* [ %34, %41 ], [ %15, %28 ]
br i1 %44, label %48, label %46
46: ; preds = %43
%47 = call i32 @sscanf(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
br label %48
48: ; preds = %11, %8, %43, %46
%49 = call i32 @fclose(i32* %6)
br label %50
50: ; preds = %48, %3
ret void
}