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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ strstr(char *, char *);
void version(const char *directory, char *major, char *minor, char *patch) {
  FILE *handle;
  char file[4096];
  size_t size = 0;
  char *data = NULL;
  snprintf(file, sizeof(file), "%s/gmqcc.h", directory);
  handle = fopen(file, "r");
  if (!handle) {
    fprintf(stderr, "failed to open %s for reading version (%s)\n", file,
            strerror(errno));
    abort();
  }
  while (getline(&data, &size, handle) != EOF) {
    if (strstr(data, "#define GMQCC_VERSION_"
                     "MAJOR")) {
      char *get = data;
      while (!isdigit(*get))
        get++;
      *major = *get;
    }
    if (strstr(data, "#define GMQCC_VERSION_"
                     "MINOR")) {
      char *get = data;
      while (!isdigit(*get))
        get++;
      *minor = *get;
    }
    if (strstr(data, "#define GMQCC_VERSION_"
                     "PATCH")) {
      char *get = data;
      while (!isdigit(*get))
        get++;
      *patch = *get;
    }
  }
  free(data);
}


x86 assembly (clang, -O0):
<version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x1038(%rbp)
movq   $0x0,-0x1040(%rbp)
lea    -0x1030(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1000,%esi
lea    0xe28(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x1030(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    124d <version+0xbd>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1064(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1060(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x1064(%rbp),%edi
mov    -0x1060(%rbp),%rdx
mov    %rax,%rcx
lea    0xdcc(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    1252 <version+0xc2>
mov    -0x28(%rbp),%rdx
lea    -0x1040(%rbp),%rdi
lea    -0x1038(%rbp),%rsi
call   1090 <getline@plt>
mov    0x2d78(%rip),%rcx
cmp    (%rcx),%rax
je     13dd <version+0x24d>
mov    -0x1040(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
je     12ee <version+0x15e>
mov    -0x1040(%rbp),%rax
mov    %rax,-0x1048(%rbp)
mov    -0x1048(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12c8 <version+0x138>
jmp    12df <version+0x14f>
mov    -0x1048(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1048(%rbp)
jmp    12a4 <version+0x114>
mov    -0x1048(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1040(%rbp),%rdi
lea    0xd59(%rip),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
je     1363 <version+0x1d3>
mov    -0x1040(%rbp),%rax
mov    %rax,-0x1050(%rbp)
mov    -0x1050(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    133d <version+0x1ad>
jmp    1354 <version+0x1c4>
mov    -0x1050(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1050(%rbp)
jmp    1319 <version+0x189>
mov    -0x1050(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1040(%rbp),%rdi
lea    0xd00(%rip),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
je     13d8 <version+0x248>
mov    -0x1040(%rbp),%rax
mov    %rax,-0x1058(%rbp)
mov    -0x1058(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    13b2 <version+0x222>
jmp    13c9 <version+0x239>
mov    -0x1058(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1058(%rbp)
jmp    138e <version+0x1fe>
mov    -0x1058(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
jmp    1252 <version+0xc2>
mov    -0x1040(%rbp),%rdi
call   1030 <free@plt>
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<version>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rcx,0x18(%rsp)
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rcx
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe38(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <snprintf@plt>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1310 <version+0x180>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
mov    0x2dda(%rip),%r14
cmp    (%r14),%rax
jne    122f <version+0x9f>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r13
jmp    1255 <version+0xc5>
cs nopw 0x0(%rax,%rax,1)
lea    0x8(%rsp),%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
cmp    (%r14),%rax
je     1213 <version+0x83>
mov    0x8(%rsp),%rdi
lea    0xdd8(%rip),%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     1288 <version+0xf8>
mov    0x8(%rsp),%rbp
movsbl 0x0(%rbp),%edi
call   1050 <isdigit@plt>
add    $0x1,%rbp
test   %eax,%eax
je     1270 <version+0xe0>
mov    -0x1(%rbp),%al
mov    %al,(%r12)
mov    0x8(%rsp),%rdi
lea    0xdc1(%rip),%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     12c7 <version+0x137>
mov    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x0(%rbp),%edi
call   1050 <isdigit@plt>
add    $0x1,%rbp
test   %eax,%eax
je     12b0 <version+0x120>
mov    -0x1(%rbp),%al
mov    %al,(%r15)
mov    0x8(%rsp),%rdi
lea    0xd9e(%rip),%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     1240 <version+0xb0>
mov    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
movsbl 0x0(%rbp),%edi
call   1050 <isdigit@plt>
add    $0x1,%rbp
test   %eax,%eax
je     12f0 <version+0x160>
mov    -0x1(%rbp),%al
mov    0x18(%rsp),%rcx
mov    %al,(%rcx)
jmp    1240 <version+0xb0>
mov    0x2cc1(%rip),%rax
mov    (%rax),%ebx
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xcdf(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"%s/gmqcc.h\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [44 x i8] c"failed to open %s for reading version (%s)\0A\00"
@errno = global i32 0
@EOF = global i64 0
@.str.3 = [28 x i8] c"#define GMQCC_VERSION_MAJOR\00"
@.str.4 = [28 x i8] c"#define GMQCC_VERSION_MINOR\00"
@.str.5 = [28 x i8] c"#define GMQCC_VERSION_PATCH\00"
define void @version(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca [4096 x i8]
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i64 0, i64* %11
store i8* null, i8** %12
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i32 @snprintf(i8* %16, i32 4096, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %9
%21 = load i32*, i32** %9
%22 = icmp ne i32* %21, null
br i1 %22, label %30, label %23
23: ; preds = %4
%24 = load i32, i32* @stderr
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* %27)
%29 = call i32 (...) @abort()
unreachable
30: ; preds = %4
br label %31
31: ; preds = %93, %30
%32 = load i32*, i32** %9
%33 = call i64 @getline(i8** %12, i64* %11, i32* %32)
%34 = load i64, i64* @EOF
%35 = icmp ne i64 %33, %34
br i1 %35, label %36, label %94
36: ; preds = %31
%37 = load i8*, i8** %12
%38 = call i64 @strstr(i8* %37, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %55
40: ; preds = %36
%41 = load i8*, i8** %12
store i8* %41, i8** %13
br label %42
42: ; preds = %48, %40
%43 = load i8*, i8** %13
%44 = load i8, i8* %43
%45 = call i32 @isdigit(i8 signext %44)
%46 = icmp ne i32 %45, 0
%47 = xor i1 %46, true
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = load i8*, i8** %13
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %13
br label %42
51: ; preds = %42
%52 = load i8*, i8** %13
%53 = load i8, i8* %52
%54 = load i8*, i8** %6
store i8 %53, i8* %54
br label %55
55: ; preds = %51, %36
%56 = load i8*, i8** %12
%57 = call i64 @strstr(i8* %56, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %74
59: ; preds = %55
%60 = load i8*, i8** %12
store i8* %60, i8** %14
br label %61
61: ; preds = %67, %59
%62 = load i8*, i8** %14
%63 = load i8, i8* %62
%64 = call i32 @isdigit(i8 signext %63)
%65 = icmp ne i32 %64, 0
%66 = xor i1 %65, true
br i1 %66, label %67, label %70
67: ; preds = %61
%68 = load i8*, i8** %14
%69 = getelementptr inbounds i8, i8* %68, i32 1
store i8* %69, i8** %14
br label %61
70: ; preds = %61
%71 = load i8*, i8** %14
%72 = load i8, i8* %71
%73 = load i8*, i8** %7
store i8 %72, i8* %73
br label %74
74: ; preds = %70, %55
%75 = load i8*, i8** %12
%76 = call i64 @strstr(i8* %75, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %93
78: ; preds = %74
%79 = load i8*, i8** %12
store i8* %79, i8** %15
br label %80
80: ; preds = %86, %78
%81 = load i8*, i8** %15
%82 = load i8, i8* %81
%83 = call i32 @isdigit(i8 signext %82)
%84 = icmp ne i32 %83, 0
%85 = xor i1 %84, true
br i1 %85, label %86, label %89
86: ; preds = %80
%87 = load i8*, i8** %15
%88 = getelementptr inbounds i8, i8* %87, i32 1
store i8* %88, i8** %15
br label %80
89: ; preds = %80
%90 = load i8*, i8** %15
%91 = load i8, i8* %90
%92 = load i8*, i8** %8
store i8 %91, i8* %92
br label %93
93: ; preds = %89, %74
br label %31
94: ; preds = %31
%95 = load i8*, i8** %12
%96 = call i32 @free(i8* %95)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s/gmqcc.h\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [44 x i8] c"failed to open %s for reading version (%s)\0A\00"
@errno = global i32 0
@EOF = global i64 0
@.str.3 = [28 x i8] c"#define GMQCC_VERSION_MAJOR\00"
@.str.4 = [28 x i8] c"#define GMQCC_VERSION_MINOR\00"
@.str.5 = [28 x i8] c"#define GMQCC_VERSION_PATCH\00"
define void @version(i8* %0, i8* nocapture writeonly %1, i8* nocapture writeonly %2, i8* nocapture writeonly %3) {
%5 = alloca [4096 x i8]
%6 = alloca i64
%7 = alloca i8*
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%9 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%10 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%11 = call i32 @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %4
%15 = call i64 @getline(i8** %7, i64* %6, i32* %12)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %70, label %24
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %21)
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %14, %66
%25 = load i8*, i8** %7
%26 = call i64 @strstr(i8* %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %38, label %28
28: ; preds = %24
%29 = load i8*, i8** %7
br label %30
30: ; preds = %30, %28
%31 = phi i8* [ %29, %28 ], [ %35, %30 ]
%32 = load i8, i8* %31
%33 = call i32 @isdigit(i8 signext %32)
%34 = icmp eq i32 %33, 0
%35 = getelementptr inbounds i8, i8* %31, i64 1
br i1 %34, label %30, label %36
36: ; preds = %30
%37 = load i8, i8* %31
store i8 %37, i8* %1
br label %38
38: ; preds = %36, %24
%39 = load i8*, i8** %7
%40 = call i64 @strstr(i8* %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %52, label %42
42: ; preds = %38
%43 = load i8*, i8** %7
br label %44
44: ; preds = %44, %42
%45 = phi i8* [ %43, %42 ], [ %49, %44 ]
%46 = load i8, i8* %45
%47 = call i32 @isdigit(i8 signext %46)
%48 = icmp eq i32 %47, 0
%49 = getelementptr inbounds i8, i8* %45, i64 1
br i1 %48, label %44, label %50
50: ; preds = %44
%51 = load i8, i8* %45
store i8 %51, i8* %2
br label %52
52: ; preds = %50, %38
%53 = load i8*, i8** %7
%54 = call i64 @strstr(i8* %53, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %66, label %56
56: ; preds = %52
%57 = load i8*, i8** %7
br label %58
58: ; preds = %58, %56
%59 = phi i8* [ %57, %56 ], [ %63, %58 ]
%60 = load i8, i8* %59
%61 = call i32 @isdigit(i8 signext %60)
%62 = icmp eq i32 %61, 0
%63 = getelementptr inbounds i8, i8* %59, i64 1
br i1 %62, label %58, label %64
64: ; preds = %58
%65 = load i8, i8* %59
store i8 %65, i8* %3
br label %66
66: ; preds = %64, %52
%67 = call i64 @getline(i8** %7, i64* %6, i32* %12)
%68 = load i64, i64* @EOF
%69 = icmp eq i64 %67, %68
br i1 %69, label %70, label %24
70: ; preds = %66, %14
%71 = load i8*, i8** %7
%72 = call i32 @free(i8* %71)
ret void
}