#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 */
scalar_t__ atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
unsigned int getgeneration() {
  char line[1024];
  char *pos, *number;
  FILE *v;
  if (!(v = fopen("version.c", "rb")))
    return 0;
  while (!feof(v)) {
    if (!fgets(line, 1024, v))
      break;
    if (!(pos = strstr(line, "#define generation")))
      continue;
    pos += strlen("#define generation");
    while (*pos && !isdigit(*pos))
      pos++;
    number = pos;
    while (*pos && isdigit(*pos))
      pos++;
    *pos = '\0';
    fclose(v);
    return (unsigned int)atoi(number) + 1;
  }
  fclose(v);
  return 0;
}


x86 assembly (clang, -O0):
<getgeneration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
lea    0xe6e(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    11bb <getgeneration+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    1364 <getgeneration+0x1e4>
jmp    11c0 <getgeneration+0x40>
mov    -0x428(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e1 <getgeneration+0x61>
jmp    1351 <getgeneration+0x1d1>
lea    -0x410(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    1207 <getgeneration+0x87>
jmp    1351 <getgeneration+0x1d1>
lea    -0x410(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
jne    1230 <getgeneration+0xb0>
jmp    11c0 <getgeneration+0x40>
lea    0xdd6(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x418(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x429(%rbp)
je     128b <getgeneration+0x10b>
mov    -0x418(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x429(%rbp)
mov    -0x429(%rbp),%al
test   $0x1,%al
jne    129e <getgeneration+0x11e>
jmp    12b5 <getgeneration+0x135>
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
jmp    1252 <getgeneration+0xd2>
mov    -0x418(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x418(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x42a(%rbp)
je     12fa <getgeneration+0x17a>
mov    -0x418(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x42a(%rbp)
mov    -0x42a(%rbp),%al
test   $0x1,%al
jne    130d <getgeneration+0x18d>
jmp    1324 <getgeneration+0x1a4>
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
jmp    12c3 <getgeneration+0x143>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x420(%rbp),%rdi
call   1090 <atoi@plt>
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1364 <getgeneration+0x1e4>
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getgeneration>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
lea    0xe69(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1080 <fopen@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1256 <getgeneration+0xd6>
mov    %rax,%r14
mov    %rsp,%r12
lea    0xe51(%rip),%r13
nopl   0x0(%rax)
mov    %r14,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    122e <getgeneration+0xae>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
je     122e <getgeneration+0xae>
mov    %r12,%rdi
mov    %r13,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11c0 <getgeneration+0x40>
mov    %rax,%rbx
mov    %rax,%r15
lea    0xe10(%rip),%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%rbx
mov    (%r15,%rax,1),%al
test   %al,%al
je     1238 <getgeneration+0xb8>
nop
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    126a <getgeneration+0xea>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
mov    %rbx,%r15
test   %al,%al
jne    1210 <getgeneration+0x90>
jmp    123b <getgeneration+0xbb>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1256 <getgeneration+0xd6>
mov    %rbx,%r15
movb   $0x0,(%r15)
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %rax,%r15
add    $0x1,%r15d
mov    %r15d,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    (%rbx),%al
mov    %rbx,%r15
test   %al,%al
je     123b <getgeneration+0xbb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     123b <getgeneration+0xbb>
movzbl 0x1(%r15),%eax
add    $0x1,%r15
test   %al,%al
jne    1280 <getgeneration+0x100>
jmp    123b <getgeneration+0xbb>

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

LLVM IR (-O2):
@.str = [10 x i8] c"version.c\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"#define generation\00"
define i32 @getgeneration() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %50, label %5
5: ; preds = %0, %11
%6 = call i32 @feof(i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %48
8: ; preds = %5
%9 = call i32 @fgets(i8* %2, i32 1024, i32* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %48, label %11
11: ; preds = %8
%12 = call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %5, label %14
14: ; preds = %11
%15 = call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %41, label %20
20: ; preds = %14, %25
%21 = phi i8 [ %27, %25 ], [ %18, %14 ]
%22 = phi i8* [ %26, %25 ], [ %17, %14 ]
%23 = call i64 @isdigit(i8 signext %21)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = getelementptr inbounds i8, i8* %22, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %41, label %20
29: ; preds = %20
%30 = load i8, i8* %22
%31 = icmp eq i8 %30, 0
br i1 %31, label %41, label %32
32: ; preds = %29, %37
%33 = phi i8 [ %39, %37 ], [ %30, %29 ]
%34 = phi i8* [ %38, %37 ], [ %22, %29 ]
%35 = call i64 @isdigit(i8 signext %33)
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %32
%38 = getelementptr inbounds i8, i8* %34, i64 1
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 0
br i1 %40, label %41, label %32
41: ; preds = %25, %32, %37, %14, %29
%42 = phi i8* [ %22, %29 ], [ %17, %14 ], [ %22, %37 ], [ %22, %32 ], [ %26, %25 ]
%43 = phi i8* [ %22, %29 ], [ %17, %14 ], [ %34, %32 ], [ %38, %37 ], [ %26, %25 ]
store i8 0, i8* %43
%44 = call i32 @fclose(i32* %3)
%45 = call i64 @atoi(i8* %42)
%46 = trunc i64 %45 to i32
%47 = add i32 %46, 1
br label %50
48: ; preds = %8, %5
%49 = call i32 @fclose(i32* %3)
br label %50
50: ; preds = %0, %48, %41
%51 = phi i32 [ %47, %41 ], [ 0, %48 ], [ 0, %0 ]
ret i32 %51
}