#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 */
int atoi(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int getMonth(char *date, int yearLow, int yearHigh) {
  if (date == NULL)
    return 0;
  if (strlen(date) < 8)
    return 0;
  char *s = (char *)malloc(5);
  strncpy(s, date + 1, 4);
  int year = atoi(s);
  if (yearLow <= year && yearHigh >= year) {
    char *s2 = (char *)malloc(3);
    strncpy(s2, date + 6, 2);
    int month = atoi(s2);
    free(s2);
    if (month > 0 && month < 13) {
      free(s);
      return month - 1;
    }
  }
  free(s);
  return -1;
}


x86 assembly (clang, -O0):
<getMonth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <getMonth+0x29>
movl   $0x0,-0x4(%rbp)
jmp    1258 <getMonth+0x108>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x8,%eax
jge    1197 <getMonth+0x47>
movl   $0x0,-0x4(%rbp)
jmp    1258 <getMonth+0x108>
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    $0x4,%edx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     1248 <getMonth+0xf8>
mov    -0x18(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     1248 <getMonth+0xf8>
mov    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x6,%rsi
mov    $0x2,%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x34(%rbp)
jle    1243 <getMonth+0xf3>
cmpl   $0xd,-0x34(%rbp)
jge    1243 <getMonth+0xf3>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <getMonth+0x108>
jmp    1248 <getMonth+0xf8>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMonth>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebp,%ebp
test   %rdi,%rdi
je     11ee <getMonth+0x9e>
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbx
call   1050 <strlen@plt>
cmp    $0x8,%eax
jl     11ee <getMonth+0x9e>
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0x1(%rbx),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1040 <strncpy@plt>
mov    %r14,%rdi
call   1070 <atoi@plt>
cmp    %r12d,%eax
jl     11e1 <getMonth+0x91>
cmp    %r15d,%eax
jg     11e1 <getMonth+0x91>
mov    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
add    $0x6,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <strncpy@plt>
mov    %r15,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebp
cmp    $0xc,%ebp
jb     11e6 <getMonth+0x96>
mov    $0xffffffff,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getMonth(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %61
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %17, 8
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 0, i32* %4
br label %61
20: ; preds = %15
%21 = call i64 @malloc(i32 5)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call i32 @strncpy(i8* %23, i8* %25, i32 4)
%27 = load i8*, i8** %8
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %9
%29 = load i32, i32* %6
%30 = load i32, i32* %9
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %58
32: ; preds = %20
%33 = load i32, i32* %7
%34 = load i32, i32* %9
%35 = icmp sge i32 %33, %34
br i1 %35, label %36, label %58
36: ; preds = %32
%37 = call i64 @malloc(i32 3)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %10
%39 = load i8*, i8** %10
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 6
%42 = call i32 @strncpy(i8* %39, i8* %41, i32 2)
%43 = load i8*, i8** %10
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %11
%45 = load i8*, i8** %10
%46 = call i32 @free(i8* %45)
%47 = load i32, i32* %11
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %36
%50 = load i32, i32* %11
%51 = icmp slt i32 %50, 13
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = load i8*, i8** %8
%54 = call i32 @free(i8* %53)
%55 = load i32, i32* %11
%56 = sub nsw i32 %55, 1
store i32 %56, i32* %4
br label %61
57: ; preds = %49, %36
br label %58
58: ; preds = %57, %32, %20
%59 = load i8*, i8** %8
%60 = call i32 @free(i8* %59)
store i32 -1, i32* %4
br label %61
61: ; preds = %58, %52, %19, %14
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
define i32 @getMonth(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %30, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp slt i32 %6, 8
br i1 %7, label %30, label %8
8: ; preds = %5
%9 = tail call i64 @malloc(i32 5)
%10 = inttoptr i64 %9 to i8*
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = tail call i32 @strncpy(i8* %10, i8* %11, i32 4)
%13 = tail call i32 @atoi(i8* %10)
%14 = icmp slt i32 %13, %1
%15 = icmp sgt i32 %13, %2
%16 = or i1 %14, %15
br i1 %16, label %26, label %17
17: ; preds = %8
%18 = tail call i64 @malloc(i32 3)
%19 = inttoptr i64 %18 to i8*
%20 = getelementptr inbounds i8, i8* %0, i64 6
%21 = tail call i32 @strncpy(i8* %19, i8* %20, i32 2)
%22 = tail call i32 @atoi(i8* %19)
%23 = tail call i32 @free(i8* %19)
%24 = add i32 %22, -1
%25 = icmp ult i32 %24, 12
br i1 %25, label %27, label %26
26: ; preds = %17, %8
br label %27
27: ; preds = %17, %26
%28 = phi i32 [ -1, %26 ], [ %24, %17 ]
%29 = tail call i32 @free(i8* %10)
br label %30
30: ; preds = %27, %5, %3
%31 = phi i32 [ 0, %3 ], [ 0, %5 ], [ %28, %27 ]
ret i32 %31
}