void get_iso_date(char *iso_date, const char *buff) {
  char month[6];
  const char *tptr, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
  int day, year, m;
  printf("# %s", buff);
  if (sscanf(buff, "%d %4s %d", &year, month, &day) != 3) {
    printf("Malformed date : '%s'\n", buff);
    exit(-1);
  }
  tptr = strstr(months, month);
  assert(tptr);
  m = tptr - months;
  assert(m % 3 == 0);
  m = m / 3 + 1;
  assert(m > 0 && m < 13);
  assert(year >= 2016 && year < 2050);
  snprintf(iso_date, 20, "%4d-%02d-%02d", year, m, day);
}


x86 assembly (clang, -O0):
<get_iso_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe89(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x16(%rbp),%rcx
lea    0xe8e(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x2c(%rbp),%r8
mov    $0x0,%al
call   1060 <sscanf@plt>
cmp    $0x3,%eax
je     11d0 <get_iso_date+0x70>
mov    -0x10(%rbp),%rsi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    -0x16(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1050 <assert@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1050 <assert@plt>
mov    -0x34(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x34(%rbp)
mov    %al,-0x35(%rbp)
jle    1241 <get_iso_date+0xe1>
cmpl   $0xd,-0x34(%rbp)
setl   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1050 <assert@plt>
xor    %eax,%eax
cmpl   $0x7e0,-0x30(%rbp)
mov    %al,-0x36(%rbp)
jl     126f <get_iso_date+0x10f>
cmpl   $0x802,-0x30(%rbp)
setl   %al
mov    %al,-0x36(%rbp)
mov    -0x36(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    $0x14,%esi
lea    0xdb2(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_iso_date>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea5(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x12(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    $0x3,%eax
jne    1254 <get_iso_date+0xf4>
lea    0xe52(%rip),%rbp
lea    0x12(%rsp),%rsi
mov    %rbp,%rdi
call   1080 <strstr@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <assert@plt>
sub    %ebp,%ebx
movslq %ebx,%rbx
imul   $0x55555556,%rbx,%rbp
mov    %rbp,%r15
shr    $0x3f,%r15
shr    $0x20,%rbp
lea    (%r15,%rbp,1),%eax
lea    (%rax,%rax,2),%eax
xor    %edi,%edi
cmp    %eax,%ebx
sete   %dil
xor    %eax,%eax
call   1050 <assert@plt>
add    %r15d,%ebp
add    $0x1,%ebp
add    $0x2,%ebx
xor    %edi,%edi
cmp    $0x26,%ebx
setb   %dil
xor    %eax,%eax
call   1050 <assert@plt>
mov    $0xfffff820,%eax
add    0x8(%rsp),%eax
xor    %edi,%edi
cmp    $0x22,%eax
setb   %dil
xor    %eax,%eax
call   1050 <assert@plt>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r9d
lea    0xe14(%rip),%rdx
mov    $0x14,%esi
mov    %r14,%rdi
mov    %ebp,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd9(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"JanFebMarAprMayJunJulAugSepOctNovDec\00"
@.str.1 = [5 x i8] c"# %s\00"
@.str.2 = [10 x i8] c"%d %4s %d\00"
@.str.3 = [23 x i8] c"Malformed date : '%s'\0A\00"
@.str.4 = [14 x i8] c"%4d-%02d-%02d\00"
define void @get_iso_date(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [6 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %7
%11 = load i8*, i8** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %4
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%15 = call i32 (i8*, i8*, ...) @sscanf(i8* %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %9, i8* %14, i32* %8)
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %18)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%23 = call i8* @strstr(i8* %21, i8* %22)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %24)
%26 = load i8*, i8** %6
%27 = load i8*, i8** %7
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = trunc i64 %30 to i32
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = srem i32 %32, 3
%34 = icmp eq i32 %33, 0
%35 = zext i1 %34 to i32
%36 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %35)
%37 = load i32, i32* %10
%38 = sdiv i32 %37, 3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %20
%43 = load i32, i32* %10
%44 = icmp slt i32 %43, 13
br label %45
45: ; preds = %42, %20
%46 = phi i1 [ false, %20 ], [ %44, %42 ]
%47 = zext i1 %46 to i32
%48 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %47)
%49 = load i32, i32* %9
%50 = icmp sge i32 %49, 2016
br i1 %50, label %51, label %54
51: ; preds = %45
%52 = load i32, i32* %9
%53 = icmp slt i32 %52, 2050
br label %54
54: ; preds = %51, %45
%55 = phi i1 [ false, %45 ], [ %53, %51 ]
%56 = zext i1 %55 to i32
%57 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %56)
%58 = load i8*, i8** %3
%59 = load i32, i32* %9
%60 = load i32, i32* %10
%61 = load i32, i32* %8
%62 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %58, i64 20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %59, i32 %60, i32 %61)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"JanFebMarAprMayJunJulAugSepOctNovDec\00"
@.str.1 = [5 x i8] c"# %s\00"
@.str.2 = [10 x i8] c"%d %4s %d\00"
@.str.3 = [23 x i8] c"Malformed date : '%s'\0A\00"
@.str.4 = [14 x i8] c"%4d-%02d-%02d\00"
define void @get_iso_date(i8* nocapture writeonly %0, i8* %1) {
%3 = alloca [6 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%10 = call i32 (i8*, i8*, ...) @sscanf(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %5, i8* %6, i32* %4)
%11 = icmp eq i32 %10, 3
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %1)
unreachable
14: ; preds = %2
%15 = call i8* @strstr(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %6)
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %15)
%17 = ptrtoint i8* %15 to i64
%18 = trunc i64 %17 to i32
%19 = sub i32 %18, ptrtoint ([37 x i8]* @.str to i32)
%20 = srem i32 %19, 3
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %22)
%24 = sdiv i32 %19, 3
%25 = add nsw i32 %24, 1
%26 = add i32 %19, 2
%27 = icmp ult i32 %26, 38
%28 = zext i1 %27 to i32
%29 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %28)
%30 = load i32, i32* %5
%31 = add i32 %30, -2016
%32 = icmp ult i32 %31, 34
%33 = zext i1 %32 to i32
%34 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %33)
%35 = load i32, i32* %5
%36 = load i32, i32* %4
%37 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* dereferenceable(1) %0, i64 20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %35, i32 %25, i32 %36)
ret void
}