#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*/ printf(char *);
int takeMonth(char *person) {
  char monthChar[1];
  int i;
  int j = 0;
  for (i = 2; i < 4; i++) {
    monthChar[j] = person[i];
    j++;
  }
  int month = atoi(monthChar);
  if (month > 0 && month < 13) {
    return month;
  }
  printf("the month you entered is not valid\n");
  return 0;
}


x86 assembly (clang, -O0):
<takeMonth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x2,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    116e <takeMonth+0x4e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x11(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <takeMonth+0x1a>
lea    -0x11(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1199 <takeMonth+0x79>
cmpl   $0xd,-0x20(%rbp)
jge    1199 <takeMonth+0x79>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <takeMonth+0x8c>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<takeMonth>:
push   %rax
mov    0x3(%rdi),%al
mov    %al,0x7(%rsp)
lea    0x7(%rsp),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
cmp    $0xc,%ecx
jb     114a <takeMonth+0x2a>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"the month you entered is not valid\0A\00"
define i32 @takeMonth(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %6
store i32 2, i32* %5
br label %8
8: ; preds = %22, %1
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 %18
store i8 %16, i8* %19
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %22
22: ; preds = %11
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %8
25: ; preds = %8
%26 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 13
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i32, i32* %7
store i32 %34, i32* %2
br label %37
35: ; preds = %30, %25
%36 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %37
37: ; preds = %35, %33
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@str = [35 x i8] c"the month you entered is not valid\00"
define i32 @takeMonth(i8* nocapture %0) {
%2 = alloca [1 x i8]
%3 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds i8, i8* %0, i64 3
%5 = load i8, i8* %4
store i8 %5, i8* %3
%6 = call i32 @atoi(i8* %3)
%7 = add i32 %6, -1
%8 = icmp ult i32 %7, 12
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %1, %9
%12 = phi i32 [ 0, %9 ], [ %6, %1 ]
ret i32 %12
}