#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 */

/* Variables and functions */
char *next_line(char const *);
int /*<<< orphan*/ parse_cpu_v15(char const *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char const *, char *, ...);
int parse(const char *b) {
  unsigned int version;
  unsigned long long ts;
  if (sscanf(b, "version %u\n", &version) != 1) {
    printf("Could not parse version\n");
    return -1;
  }
  switch (version) {
  case 15:
    b = next_line(b);
    if (!b || sscanf(b, "timestamp %llu\n", &ts) != 1) {
      printf("Could not parse timestamp\n");
      return -1;
    }
    while (1) {
      b = next_line(b);
      if (!b)
        break;
      if (b[0] == 'c') {
        if (parse_cpu_v15(b))
          return -1;
      }
    }
    break;
  default:
    printf("Can not handle version %u\n", version);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xefc(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1185 <parse+0x45>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <parse+0x12a>
mov    -0x14(%rbp),%eax
sub    $0xf,%eax
jne    1246 <parse+0x106>
jmp    1196 <parse+0x56>
mov    -0x10(%rbp),%rdi
call   1040 <next_line@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11cd <parse+0x8d>
mov    -0x10(%rbp),%rdi
lea    0xe60(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11e7 <parse+0xa7>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <parse+0x12a>
jmp    11ec <parse+0xac>
mov    -0x10(%rbp),%rdi
call   1040 <next_line@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1209 <parse+0xc9>
jmp    1241 <parse+0x101>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x63,%eax
jne    123c <parse+0xfc>
mov    -0x10(%rbp),%rdi
call   1060 <parse_cpu_v15@plt>
cmp    $0x0,%eax
je     1237 <parse+0xf7>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <parse+0x12a>
jmp    123c <parse+0xfc>
jmp    11ec <parse+0xac>
jmp    1263 <parse+0x123>
mov    -0x14(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <parse+0x12a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xebf(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11e3 <parse+0x93>
mov    0xc(%rsp),%esi
cmp    $0xf,%esi
jne    11ec <parse+0x9c>
mov    %rbx,%rdi
call   1050 <next_line@plt>
test   %rax,%rax
je     11fc <parse+0xac>
mov    %rax,%rbx
lea    0xe6f(%rip),%rsi
xor    %ebp,%ebp
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11fc <parse+0xac>
mov    %rbx,%rdi
call   1050 <next_line@plt>
test   %rax,%rax
je     120d <parse+0xbd>
mov    %rax,%rbx
jmp    11d0 <parse+0x80>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <next_line@plt>
mov    %rax,%rbx
test   %rax,%rax
je     120d <parse+0xbd>
cmpb   $0x63,(%rbx)
jne    11c0 <parse+0x70>
mov    %rbx,%rdi
call   1070 <parse_cpu_v15@plt>
test   %eax,%eax
je     11c0 <parse+0x70>
jmp    1208 <parse+0xb8>
lea    0xe5b(%rip),%rdi
jmp    1203 <parse+0xb3>
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1208 <parse+0xb8>
lea    0xe28(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"version %u\0A\00"
@.str.1 = [25 x i8] c"Could not parse version\0A\00"
@.str.2 = [16 x i8] c"timestamp %llu\0A\00"
@.str.3 = [27 x i8] c"Could not parse timestamp\0A\00"
@.str.4 = [27 x i8] c"Can not handle version %u\0A\00"
define i32 @parse(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 (i8*, i8*, ...) @sscanf(i8* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %4)
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %49
11: ; preds = %1
%12 = load i32, i32* %4
switch i32 %12, label %45 [
i32 15, label %13
]
13: ; preds = %11
%14 = load i8*, i8** %3
%15 = call i8* @next_line(i8* %14)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 (i8*, i8*, ...) @sscanf(i8* %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64* %5)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %18, %13
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %49
24: ; preds = %18
br label %25
25: ; preds = %24, %43
%26 = load i8*, i8** %3
%27 = call i8* @next_line(i8* %26)
store i8* %27, i8** %3
%28 = load i8*, i8** %3
%29 = icmp ne i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %25
br label %44
31: ; preds = %25
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 99
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = load i8*, i8** %3
%39 = call i32 @parse_cpu_v15(i8* %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 -1, i32* %2
br label %49
42: ; preds = %37
br label %43
43: ; preds = %42, %31
br label %25
44: ; preds = %30
br label %48
45: ; preds = %11
%46 = load i32, i32* %4
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %46)
store i32 -1, i32* %2
br label %49
48: ; preds = %44
store i32 0, i32* %2
br label %49
49: ; preds = %48, %45, %41, %22, %9
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@.str = [12 x i8] c"version %u\0A\00"
@.str.2 = [16 x i8] c"timestamp %llu\0A\00"
@.str.4 = [27 x i8] c"Can not handle version %u\0A\00"
@str = [26 x i8] c"Could not parse timestamp\00"
@str.5 = [24 x i8] c"Could not parse version\00"
define i32 @parse(i8* %0) {
%2 = alloca i32
%3 = alloca i64
%4 = bitcast i32* %2 to i8*
%5 = bitcast i64* %3 to i8*
%6 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
br label %36
10: ; preds = %1
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 15
br i1 %12, label %13, label %34
13: ; preds = %10
%14 = call i8* @next_line(i8* %0)
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = call i32 (i8*, i8*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64* %3)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i8* @next_line(i8* %14)
%21 = icmp eq i8* %20, null
br i1 %21, label %36, label %24
22: ; preds = %16, %13
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %36
24: ; preds = %19, %31
%25 = phi i8* [ %32, %31 ], [ %20, %19 ]
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 99
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 @parse_cpu_v15(i8* %25)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28, %24
%32 = call i8* @next_line(i8* %25)
%33 = icmp eq i8* %32, null
br i1 %33, label %36, label %24
34: ; preds = %10
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %11)
br label %36
36: ; preds = %28, %31, %19, %34, %22, %8
%37 = phi i32 [ -1, %8 ], [ -1, %22 ], [ -1, %34 ], [ 0, %19 ], [ -1, %28 ], [ 0, %31 ]
ret i32 %37
}