#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*/ getchar();
int /*<<< orphan*/ gets(char *);
scalar_t__ isalpha(char);
int /*<<< orphan*/ printf(char *);
scalar_t__ strlen(char *);
int main() {
  char s[10];
  int year;
  do {
    printf("Enter 4 digit year: ");
    gets(s);
  } while ((unsigned)strlen(s) > 4);
  int isNumber = 0;
  for (int i = 0; i < (unsigned)strlen(s); i++) {
    if (isalpha(s[i]) == 0) {
      isNumber = 1;
    } else {
      isNumber = 0;
      break;
    }
  }
  while (!isNumber) {
    printf("Enter only digits: ");
    gets(s);
    int isNumber = 0;
    for (int i = 0; i < (unsigned)strlen(s); i++) {
      if (isalpha(s[i]) == 0) {
        isNumber = 1;
      } else {
        return isNumber = 0;
      }
    }
  }
  year = atoi(s);
  if ((year % 4 != 0) || (year % 400 != 0)) {
    printf("It's not a leap year");
  } else if (year % 100 != 0) {
    printf("It's a leap year");
  } else {
    printf("It's a leap year");
  }
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
lea    -0xe(%rbp),%rdi
call   1060 <gets@plt>
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
ja     116f <main+0xf>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jae    1204 <main+0xa4>
movslq -0x1c(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1070 <isalpha@plt>
cmp    $0x0,%rax
jne    11e5 <main+0x85>
movl   $0x1,-0x18(%rbp)
jmp    11f1 <main+0x91>
movl   $0x0,-0x18(%rbp)
jmp    1204 <main+0xa4>
jmp    11f6 <main+0x96>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a4 <main+0x44>
jmp    1209 <main+0xa9>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    121f <main+0xbf>
jmp    12ae <main+0x14e>
lea    0xdef(%rip),%rdi
call   1040 <printf@plt>
lea    -0xe(%rbp),%rdi
call   1060 <gets@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jae    12a9 <main+0x149>
movslq -0x24(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1070 <isalpha@plt>
cmp    $0x0,%rax
jne    1283 <main+0x123>
movl   $0x1,-0x20(%rbp)
jmp    1296 <main+0x136>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    1337 <main+0x1d7>
jmp    129b <main+0x13b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1242 <main+0xe2>
jmp    1209 <main+0xa9>
lea    -0xe(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12e2 <main+0x182>
mov    -0x14(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12f3 <main+0x193>
lea    0xd40(%rip),%rdi
call   1040 <printf@plt>
jmp    1329 <main+0x1c9>
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1318 <main+0x1b8>
lea    0xd30(%rip),%rdi
call   1040 <printf@plt>
jmp    1324 <main+0x1c4>
lea    0xd1f(%rip),%rdi
call   1040 <printf@plt>
jmp    1329 <main+0x1c9>
mov    $0x0,%al
call   1050 <getchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%r14
lea    0x6(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <gets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
ja     1180 <main+0x20>
test   %eax,%eax
je     122a <main+0xca>
xor    %ebx,%ebx
lea    0x6(%rsp),%r14
nopl   0x0(%rax)
movsbl 0x6(%rsp,%rbx,1),%edi
call   1070 <isalpha@plt>
test   %rax,%rax
jne    122a <main+0xca>
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     11b0 <main+0x50>
lea    0x6(%rsp),%rdi
call   1080 <atoi@plt>
movslq %eax,%rcx
and    $0x3,%eax
imul   $0x51eb851f,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x27,%rdx
add    %esi,%edx
imul   $0x190,%edx,%edx
sub    %edx,%ecx
or     %eax,%ecx
lea    0xe37(%rip),%rax
lea    0xe1b(%rip),%rdi
cmove  %rax,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xde4(%rip),%r14
lea    0x6(%rsp),%r15
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1060 <gets@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1236 <main+0xd6>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x6(%rsp,%rbx,1),%edi
call   1070 <isalpha@plt>
test   %rax,%rax
jne    121e <main+0xbe>
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1260 <main+0x100>
jmp    1236 <main+0xd6>

LLVM IR (-O0):
@.str = [21 x i8] c"Enter 4 digit year: \00"
@.str.1 = [20 x i8] c"Enter only digits: \00"
@.str.2 = [21 x i8] c"It's not a leap year\00"
@.str.3 = [17 x i8] c"It's a leap year\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
br label %8
8: ; preds = %12, %0
%9 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%11 = call i32 @gets(i8* %10)
br label %12
12: ; preds = %8
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%14 = call i64 @strlen(i8* %13)
%15 = trunc i64 %14 to i32
%16 = icmp ugt i32 %15, 4
br i1 %16, label %8, label %17
17: ; preds = %12
store i32 0, i32* %4
store i32 0, i32* %5
br label %18
18: ; preds = %34, %17
%19 = load i32, i32* %5
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%21 = call i64 @strlen(i8* %20)
%22 = trunc i64 %21 to i32
%23 = icmp ult i32 %19, %22
br i1 %23, label %24, label %37
24: ; preds = %18
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = call i64 @isalpha(i8 signext %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %4
br label %33
32: ; preds = %24
store i32 0, i32* %4
br label %37
33: ; preds = %31
br label %34
34: ; preds = %33
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %18
37: ; preds = %32, %18
br label %38
38: ; preds = %65, %37
%39 = load i32, i32* %4
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
br i1 %41, label %42, label %66
42: ; preds = %38
%43 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%44 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%45 = call i32 @gets(i8* %44)
store i32 0, i32* %6
store i32 0, i32* %7
br label %46
46: ; preds = %62, %42
%47 = load i32, i32* %7
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%49 = call i64 @strlen(i8* %48)
%50 = trunc i64 %49 to i32
%51 = icmp ult i32 %47, %50
br i1 %51, label %52, label %65
52: ; preds = %46
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = call i64 @isalpha(i8 signext %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %52
store i32 1, i32* %6
br label %61
60: ; preds = %52
store i32 0, i32* %6
store i32 0, i32* %1
br label %89
61: ; preds = %59
br label %62
62: ; preds = %61
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %7
br label %46
65: ; preds = %46
br label %38
66: ; preds = %38
%67 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%68 = call i32 @atoi(i8* %67)
store i32 %68, i32* %3
%69 = load i32, i32* %3
%70 = srem i32 %69, 4
%71 = icmp ne i32 %70, 0
br i1 %71, label %76, label %72
72: ; preds = %66
%73 = load i32, i32* %3
%74 = srem i32 %73, 400
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %72, %66
%77 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %87
78: ; preds = %72
%79 = load i32, i32* %3
%80 = srem i32 %79, 100
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %78
%83 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %86
84: ; preds = %78
%85 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %86
86: ; preds = %84, %82
br label %87
87: ; preds = %86, %76
%88 = call i32 (...) @getchar()
store i32 0, i32* %1
br label %89
89: ; preds = %87, %60
%90 = load i32, i32* %1
ret i32 %90
}

LLVM IR (-O2):
@.str = [21 x i8] c"Enter 4 digit year: \00"
@.str.1 = [20 x i8] c"Enter only digits: \00"
@.str.2 = [21 x i8] c"It's not a leap year\00"
@.str.3 = [17 x i8] c"It's a leap year\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %3, %0
%4 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @gets(i8* %2)
%6 = call i64 @strlen(i8* %2)
%7 = trunc i64 %6 to i32
%8 = icmp ugt i32 %7, 4
br i1 %8, label %3, label %9
9: ; preds = %3
%10 = trunc i64 %6 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %23, label %16
12: ; preds = %16
%13 = call i64 @strlen(i8* %2)
%14 = and i64 %13, 4294967295
%15 = icmp ult i64 %22, %14
br i1 %15, label %16, label %42
16: ; preds = %9, %12
%17 = phi i64 [ %22, %12 ], [ 0, %9 ]
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @isalpha(i8 signext %19)
%21 = icmp eq i64 %20, 0
%22 = add nuw nsw i64 %17, 1
br i1 %21, label %12, label %23
23: ; preds = %16, %9
br label %24
24: ; preds = %30, %23
%25 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @gets(i8* %2)
%27 = call i64 @strlen(i8* %2)
%28 = trunc i64 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %31, %24
br label %24
31: ; preds = %35
%32 = call i64 @strlen(i8* %2)
%33 = and i64 %32, 4294967295
%34 = icmp ult i64 %41, %33
br i1 %34, label %35, label %30
35: ; preds = %24, %31
%36 = phi i64 [ %41, %31 ], [ 0, %24 ]
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = call i64 @isalpha(i8 signext %38)
%40 = icmp eq i64 %39, 0
%41 = add nuw nsw i64 %36, 1
br i1 %40, label %31, label %51
42: ; preds = %12
%43 = call i32 @atoi(i8* %2)
%44 = and i32 %43, 3
%45 = srem i32 %43, 400
%46 = or i32 %44, %45
%47 = icmp eq i32 %46, 0
%48 = select i1 %47, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0)
%49 = call i32 @printf(i8* dereferenceable(1) %48)
%50 = call i32 (...) @getchar()
br label %51
51: ; preds = %35, %42
ret i32 0
}