#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 /*<<< orphan*/ memmove(char *, char const *, int);
void fix_date(char *buf) {
  const char *ptr = buf;
  int ch, len = 0;
  do {
    ch = *ptr++;
    if (ch >= '0' && ch <= '9') {
      len++;
      continue;
    }
    if (len == 4) {
      memmove(buf, ptr - 5, 4);
      buf[4] = 0;
      return;
    }
    len = 0;
  } while (ch);
  *buf = 0;
}


x86 assembly (clang, -O0):
<fix_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x30,-0x14(%rbp)
jl     1162 <fix_date+0x52>
cmpl   $0x39,-0x14(%rbp)
jg     1162 <fix_date+0x52>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1196 <fix_date+0x86>
cmpl   $0x4,-0x18(%rbp)
jne    118f <fix_date+0x7f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xfffffffffffffffb,%rsi
mov    $0x4,%edx
call   1030 <memmove@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0x4(%rax)
jmp    11a7 <fix_date+0x97>
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    112b <fix_date+0x1b>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fix_date>:
push   %rbx
mov    %rdi,%rbx
lea    -0x4(%rdi),%rsi
xor    %eax,%eax
jmp    112b <fix_date+0x1b>
nopl   0x0(%rax)
add    $0x1,%eax
add    $0x1,%rsi
test   %cl,%cl
je     1152 <fix_date+0x42>
movzbl 0x4(%rsi),%ecx
lea    -0x30(%rcx),%edx
cmp    $0x9,%dl
jbe    1120 <fix_date+0x10>
cmp    $0x4,%eax
mov    $0x0,%eax
jne    1123 <fix_date+0x13>
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memmove@plt>
add    $0x4,%rbx
movb   $0x0,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @fix_date(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
store i32 0, i32* %5
br label %7
7: ; preds = %31, %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %3
%10 = load i8, i8* %8
%11 = sext i8 %10 to i32
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 48
br i1 %13, label %14, label %20
14: ; preds = %7
%15 = load i32, i32* %4
%16 = icmp sle i32 %15, 57
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %31
20: ; preds = %14, %7
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 4
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i8*, i8** %2
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 -5
%27 = call i32 @memmove(i8* %24, i8* %26, i32 4)
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i64 4
store i8 0, i8* %29
br label %36
30: ; preds = %20
store i32 0, i32* %5
br label %31
31: ; preds = %30, %17
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 0
br i1 %33, label %7, label %34
34: ; preds = %31
%35 = load i8*, i8** %2
store i8 0, i8* %35
br label %36
36: ; preds = %34, %23
ret void
}

LLVM IR (-O2):
define void @fix_date(i8* %0) {
br label %2
2: ; preds = %17, %1
%3 = phi i8* [ %0, %1 ], [ %5, %17 ]
%4 = phi i32 [ 0, %1 ], [ %18, %17 ]
%5 = getelementptr inbounds i8, i8* %3, i64 1
%6 = load i8, i8* %3
%7 = add i8 %6, -48
%8 = icmp ult i8 %7, 10
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = add nsw i32 %4, 1
br label %17
11: ; preds = %2
%12 = icmp eq i32 %4, 4
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = getelementptr inbounds i8, i8* %3, i64 -4
%15 = tail call i32 @memmove(i8* %0, i8* %14, i32 4)
%16 = getelementptr inbounds i8, i8* %0, i64 4
br label %20
17: ; preds = %11, %9
%18 = phi i32 [ %10, %9 ], [ 0, %11 ]
%19 = icmp eq i8 %6, 0
br i1 %19, label %20, label %2
20: ; preds = %17, %13
%21 = phi i8* [ %16, %13 ], [ %0, %17 ]
store i8 0, i8* %21
ret void
}