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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  int major, minor, len;
  char ver[40];
  if (argc != 3) {
    fprintf(stderr, "Usage: ver2h version version.h\n");
    return 1;
  }
  in = fopen(argv[1], "rt");
  if (!in) {
    fprintf(stderr, "ver2h: open %s fail\n", argv[1]);
    return 1;
  }
  ver[0] = 0;
  fgets(ver, sizeof(ver), in);
  len = strlen(ver) - 1;
  while ((len >= 0) && ((ver[len] == '\r') || (ver[len] == '\n')))
    len--;
  ver[len + 1] = 0;
  sscanf(ver, "%d.%d", &major, &minor);
  fclose(in);
  out = fopen(argv[2], "wt");
  if (!out) {
    fclose(in);
    fprintf(stderr, "ver2h: open %s fail\n", argv[2]);
    return 1;
  }
  fprintf(out, "#define VERSION \"%s\"\n", ver);
  fprintf(out, "#define VER_MAJOR %d\n", major);
  fprintf(out, "#define VER_MINOR %d\n", minor);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a4 <main+0x44>
mov    0x2e59(%rip),%rax
movslq (%rax),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    134a <main+0x1ea>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f3 <main+0x93>
mov    0x2e12(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    134a <main+0x1ea>
movb   $0x0,-0x60(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x28,%esi
call   1050 <fgets@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x61(%rbp)
jl     1256 <main+0xf6>
movslq -0x2c(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x62(%rbp)
je     1250 <main+0xf0>
movslq -0x2c(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x62(%rbp)
mov    -0x62(%rbp),%al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
test   $0x1,%al
jne    1266 <main+0x106>
jmp    1274 <main+0x114>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    1218 <main+0xb8>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
lea    0xdac(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1070 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd8d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12fa <main+0x19a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d0b(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd3c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    134a <main+0x1ea>
mov    -0x20(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xd38(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xd3a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
cmp    $0x3,%edi
jne    11f4 <main+0x84>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe94(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1219 <main+0xa9>
mov    %rax,%r14
movb   $0x0,0x10(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x28,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    122e <main+0xbe>
mov    %eax,%eax
jmp    11dd <main+0x6d>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rdx
mov    %rcx,%rax
cmp    $0x1,%rdx
jbe    122c <main+0xbc>
lea    -0x1(%rax),%rcx
mov    %ecx,%edx
movzbl 0x10(%rsp,%rdx,1),%edx
cmp    $0xd,%dl
je     11d0 <main+0x60>
cmp    $0xa,%dl
je     11d0 <main+0x60>
jmp    122e <main+0xbe>
mov    0x2de5(%rip),%rax
movslq (%rax),%rcx
lea    0xdfb(%rip),%rdi
mov    $0x1f,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
jmp    12e0 <main+0x170>
mov    0x2dc0(%rip),%rax
movslq (%rax),%rdi
mov    0x8(%rbx),%rdx
jmp    12d2 <main+0x162>
xor    %eax,%eax
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xdfc(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1070 <sscanf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x10(%rbx),%rdi
lea    0xddb(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12bc <main+0x14c>
mov    %rax,%r15
lea    0xdca(%rip),%rsi
xor    %ebx,%ebx
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0xc(%rsp),%edx
lea    0xdc4(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rsp),%edx
lea    0xdc5(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    12e5 <main+0x175>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2d15(%rip),%rax
movslq (%rax),%rdi
mov    0x10(%rbx),%rdx
lea    0xd4a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: ver2h version version.h\0A\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [21 x i8] c"ver2h: open %s fail\0A\00"
@.str.3 = [6 x i8] c"%d.%d\00"
@.str.4 = [3 x i8] c"wt\00"
@.str.5 = [22 x i8] c"#define VERSION \22%s\22\0A\00"
@.str.6 = [22 x i8] c"#define VER_MAJOR %d\0A\00"
@.str.7 = [22 x i8] c"#define VER_MINOR %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [40 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %103
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp ne i32* %24, null
br i1 %25, label %34, label %26
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 1, i32* %3
br label %103
34: ; preds = %19
%35 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 0
store i8 0, i8* %35
%36 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 0
%37 = load i32*, i32** %6
%38 = call i32 @fgets(i8* %36, i32 40, i32* %37)
%39 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = sub nsw i32 %40, 1
store i32 %41, i32* %10
br label %42
42: ; preds = %63, %34
%43 = load i32, i32* %10
%44 = icmp sge i32 %43, 0
br i1 %44, label %45, label %61
45: ; preds = %42
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 13
br i1 %51, label %59, label %52
52: ; preds = %45
%53 = load i32, i32* %10
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 10
br label %59
59: ; preds = %52, %45
%60 = phi i1 [ true, %45 ], [ %58, %52 ]
br label %61
61: ; preds = %59, %42
%62 = phi i1 [ false, %42 ], [ %60, %59 ]
br i1 %62, label %63, label %66
63: ; preds = %61
%64 = load i32, i32* %10
%65 = add nsw i32 %64, -1
store i32 %65, i32* %10
br label %42
66: ; preds = %61
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 %69
store i8 0, i8* %70
%71 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 0
%72 = call i32 @sscanf(i8* %71, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %8, i32* %9)
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 2
%77 = load i8*, i8** %76
%78 = call i32* @fopen(i8* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %78, i32** %7
%79 = load i32*, i32** %7
%80 = icmp ne i32* %79, null
br i1 %80, label %91, label %81
81: ; preds = %66
%82 = load i32*, i32** %6
%83 = call i32 @fclose(i32* %82)
%84 = load i32, i32* @stderr
%85 = sext i32 %84 to i64
%86 = inttoptr i64 %85 to i32*
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 2
%89 = load i8*, i8** %88
%90 = call i32 (i32*, i8*, ...) @fprintf(i32* %86, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %89)
store i32 1, i32* %3
br label %103
91: ; preds = %66
%92 = load i32*, i32** %7
%93 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 0
%94 = call i32 (i32*, i8*, ...) @fprintf(i32* %92, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %93)
%95 = load i32*, i32** %7
%96 = load i32, i32* %8
%97 = call i32 (i32*, i8*, ...) @fprintf(i32* %95, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %96)
%98 = load i32*, i32** %7
%99 = load i32, i32* %9
%100 = call i32 (i32*, i8*, ...) @fprintf(i32* %98, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %99)
%101 = load i32*, i32** %7
%102 = call i32 @fclose(i32* %101)
store i32 0, i32* %3
br label %103
103: ; preds = %91, %81, %26, %14
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: ver2h version version.h\0A\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [21 x i8] c"ver2h: open %s fail\0A\00"
@.str.3 = [6 x i8] c"%d.%d\00"
@.str.4 = [3 x i8] c"wt\00"
@.str.5 = [22 x i8] c"#define VERSION \22%s\22\0A\00"
@.str.6 = [22 x i8] c"#define VER_MAJOR %d\0A\00"
@.str.7 = [22 x i8] c"#define VER_MINOR %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [40 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i64 31, i64 1, i32* %13)
br label %66
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i32*
%24 = load i8*, i8** %16
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %66
26: ; preds = %15
store i8 0, i8* %8
%27 = call i32 @fgets(i8* %8, i32 40, i32* %18)
%28 = call i32 @strlen(i8* %8)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %26
%31 = zext i32 %28 to i64
br label %32
32: ; preds = %30, %38
%33 = phi i64 [ %31, %30 ], [ %34, %38 ]
%34 = add nsw i64 %33, -1
%35 = and i64 %34, 4294967295
%36 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 %35
%37 = load i8, i8* %36
switch i8 %37, label %40 [
i8 13, label %38
i8 10, label %38
]
38: ; preds = %32, %32
%39 = icmp ugt i64 %33, 1
br i1 %39, label %32, label %42
40: ; preds = %32
%41 = trunc i64 %33 to i32
br label %42
42: ; preds = %38, %40, %26
%43 = phi i32 [ %28, %26 ], [ %41, %40 ], [ 0, %38 ]
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 %44
store i8 0, i8* %45
%46 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4)
%47 = call i32 @fclose(i32* %18)
%48 = getelementptr inbounds i8*, i8** %1, i64 2
%49 = load i8*, i8** %48
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %59
52: ; preds = %42
%53 = call i32 @fclose(i32* %18)
%54 = load i32, i32* @stderr
%55 = sext i32 %54 to i64
%56 = inttoptr i64 %55 to i32*
%57 = load i8*, i8** %48
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %57)
br label %66
59: ; preds = %42
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%61 = load i32, i32* %3
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %4
%64 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %63)
%65 = call i32 @fclose(i32* %50)
br label %66
66: ; preds = %59, %52, %20, %10
%67 = phi i32 [ 1, %10 ], [ 0, %59 ], [ 1, %52 ], [ 1, %20 ]
ret i32 %67
}