#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 */
typedef int uint32_t;

/* Variables and functions */
size_t strlen(char *);
int /*<<< orphan*/ strrev(char *, char *);
int to_u32(char *, int, int);
void split_sn(char *s, uint32_t *sn) {
  size_t len = strlen(s);
  if (len == 14) {
    sn[5] = 0;
    sn[0] = to_u32(s, 0, 5);
    sn[1] = to_u32(s, 5, 1);
    sn[2] = to_u32(s, 6, 2);
    sn[3] = to_u32(s, 8, 1);
    sn[4] = to_u32(s, 9, 5);
  } else if (len == 12) {
    char rev[13];
    strrev(rev, s);
    sn[5] = 1;
    sn[0] = to_u32(rev, 0, 4);
    sn[1] = to_u32(rev, 4, 1);
    sn[2] = to_u32(rev, 5, 2);
    sn[3] = to_u32(rev, 7, 1);
    uint32_t v1 = 0;
    size_t i = 8;
    for (; i < 12; ++i) {
      uint32_t v0 = ((v1 << 2) + v1) << 1;
      v1 = v0 + (rev[i] - '0');
    }
    sn[4] = v1;
  }
}


x86 assembly (clang, -O0):
<split_sn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xe,-0x18(%rbp)
jne    11f0 <split_sn+0xc0>
mov    -0x10(%rbp),%rax
movl   $0x0,0x14(%rax)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <to_u32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
call   1050 <to_u32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x6,%esi
mov    $0x2,%edx
call   1050 <to_u32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <to_u32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x9,%esi
mov    $0x5,%edx
call   1050 <to_u32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
jmp    12dc <split_sn+0x1ac>
cmpq   $0xc,-0x18(%rbp)
jne    12d7 <split_sn+0x1a7>
lea    -0x25(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strrev@plt>
mov    -0x10(%rbp),%rax
movl   $0x1,0x14(%rax)
lea    -0x25(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <to_u32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x25(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <to_u32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
lea    -0x25(%rbp),%rdi
mov    $0x5,%esi
mov    $0x2,%edx
call   1050 <to_u32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
lea    -0x25(%rbp),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
call   1050 <to_u32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
movl   $0x0,-0x2c(%rbp)
movq   $0x8,-0x38(%rbp)
cmpq   $0xc,-0x38(%rbp)
jae    12cd <split_sn+0x19d>
mov    -0x2c(%rbp),%eax
shl    $0x2,%eax
add    -0x2c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x38(%rbp),%rcx
movsbl -0x25(%rbp,%rcx,1),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    128e <split_sn+0x15e>
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
jmp    12dc <split_sn+0x1ac>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_sn>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0xc,%rax
je     11c7 <split_sn+0x97>
cmp    $0xe,%rax
jne    1262 <split_sn+0x132>
movl   $0x0,0x14(%r14)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <to_u32@plt>
mov    %eax,(%r14)
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x1,%edx
call   1050 <to_u32@plt>
mov    %eax,0x4(%r14)
mov    %rbx,%rdi
mov    $0x6,%esi
mov    $0x2,%edx
call   1050 <to_u32@plt>
mov    %eax,0x8(%r14)
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <to_u32@plt>
mov    %eax,0xc(%r14)
mov    %rbx,%rdi
mov    $0x9,%esi
mov    $0x5,%edx
call   1050 <to_u32@plt>
jmp    125e <split_sn+0x12e>
lea    0x3(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strrev@plt>
movl   $0x1,0x14(%r14)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <to_u32@plt>
mov    %eax,(%r14)
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <to_u32@plt>
mov    %eax,0x4(%r14)
mov    %r15,%rdi
mov    $0x5,%esi
mov    $0x2,%edx
call   1050 <to_u32@plt>
mov    %eax,0x8(%r14)
mov    %r15,%rdi
mov    $0x7,%esi
mov    $0x1,%edx
call   1050 <to_u32@plt>
mov    %eax,0xc(%r14)
movsbl 0xb(%rsp),%eax
lea    (%rax,%rax,4),%eax
movsbl 0xc(%rsp),%ecx
lea    (%rcx,%rax,2),%eax
lea    (%rax,%rax,4),%eax
movsbl 0xd(%rsp),%ecx
lea    (%rcx,%rax,2),%eax
lea    (%rax,%rax,4),%eax
movsbl 0xe(%rsp),%ecx
lea    (%rcx,%rax,2),%eax
add    $0xffff2fb0,%eax
mov    %eax,0x10(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @split_sn(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca [13 x i8]
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = icmp eq i64 %12, 14
br i1 %13, label %14, label %37
14: ; preds = %2
%15 = load i32*, i32** %4
%16 = getelementptr inbounds i32, i32* %15, i64 5
store i32 0, i32* %16
%17 = load i8*, i8** %3
%18 = call i32 @to_u32(i8* %17, i32 0, i32 5)
%19 = load i32*, i32** %4
%20 = getelementptr inbounds i32, i32* %19, i64 0
store i32 %18, i32* %20
%21 = load i8*, i8** %3
%22 = call i32 @to_u32(i8* %21, i32 5, i32 1)
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 1
store i32 %22, i32* %24
%25 = load i8*, i8** %3
%26 = call i32 @to_u32(i8* %25, i32 6, i32 2)
%27 = load i32*, i32** %4
%28 = getelementptr inbounds i32, i32* %27, i64 2
store i32 %26, i32* %28
%29 = load i8*, i8** %3
%30 = call i32 @to_u32(i8* %29, i32 8, i32 1)
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 3
store i32 %30, i32* %32
%33 = load i8*, i8** %3
%34 = call i32 @to_u32(i8* %33, i32 9, i32 5)
%35 = load i32*, i32** %4
%36 = getelementptr inbounds i32, i32* %35, i64 4
store i32 %34, i32* %36
br label %86
37: ; preds = %2
%38 = load i64, i64* %5
%39 = icmp eq i64 %38, 12
br i1 %39, label %40, label %85
40: ; preds = %37
%41 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%42 = load i8*, i8** %3
%43 = call i32 @strrev(i8* %41, i8* %42)
%44 = load i32*, i32** %4
%45 = getelementptr inbounds i32, i32* %44, i64 5
store i32 1, i32* %45
%46 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%47 = call i32 @to_u32(i8* %46, i32 0, i32 4)
%48 = load i32*, i32** %4
%49 = getelementptr inbounds i32, i32* %48, i64 0
store i32 %47, i32* %49
%50 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%51 = call i32 @to_u32(i8* %50, i32 4, i32 1)
%52 = load i32*, i32** %4
%53 = getelementptr inbounds i32, i32* %52, i64 1
store i32 %51, i32* %53
%54 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%55 = call i32 @to_u32(i8* %54, i32 5, i32 2)
%56 = load i32*, i32** %4
%57 = getelementptr inbounds i32, i32* %56, i64 2
store i32 %55, i32* %57
%58 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%59 = call i32 @to_u32(i8* %58, i32 7, i32 1)
%60 = load i32*, i32** %4
%61 = getelementptr inbounds i32, i32* %60, i64 3
store i32 %59, i32* %61
store i32 0, i32* %7
store i64 8, i64* %8
br label %62
62: ; preds = %78, %40
%63 = load i64, i64* %8
%64 = icmp ult i64 %63, 12
br i1 %64, label %65, label %81
65: ; preds = %62
%66 = load i32, i32* %7
%67 = shl i32 %66, 2
%68 = load i32, i32* %7
%69 = add nsw i32 %67, %68
%70 = shl i32 %69, 1
store i32 %70, i32* %9
%71 = load i32, i32* %9
%72 = load i64, i64* %8
%73 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 %72
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = sub nsw i32 %75, 48
%77 = add nsw i32 %71, %76
store i32 %77, i32* %7
br label %78
78: ; preds = %65
%79 = load i64, i64* %8
%80 = add i64 %79, 1
store i64 %80, i64* %8
br label %62
81: ; preds = %62
%82 = load i32, i32* %7
%83 = load i32*, i32** %4
%84 = getelementptr inbounds i32, i32* %83, i64 4
store i32 %82, i32* %84
br label %85
85: ; preds = %81, %37
br label %86
86: ; preds = %85, %14
ret void
}

LLVM IR (-O2):
define void @split_sn(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [13 x i8]
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
switch i64 %4, label %49 [
i64 14, label %5
i64 12, label %16
]
5: ; preds = %2
%6 = getelementptr inbounds i32, i32* %1, i64 5
store i32 0, i32* %6
%7 = tail call i32 @to_u32(i8* %0, i32 0, i32 5)
store i32 %7, i32* %1
%8 = tail call i32 @to_u32(i8* %0, i32 5, i32 1)
%9 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %8, i32* %9
%10 = tail call i32 @to_u32(i8* %0, i32 6, i32 2)
%11 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %10, i32* %11
%12 = tail call i32 @to_u32(i8* %0, i32 8, i32 1)
%13 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %12, i32* %13
%14 = tail call i32 @to_u32(i8* %0, i32 9, i32 5)
%15 = getelementptr inbounds i32, i32* %1, i64 4
store i32 %14, i32* %15
br label %49
16: ; preds = %2
%17 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%18 = call i32 @strrev(i8* %17, i8* %0)
%19 = getelementptr inbounds i32, i32* %1, i64 5
store i32 1, i32* %19
%20 = call i32 @to_u32(i8* %17, i32 0, i32 4)
store i32 %20, i32* %1
%21 = call i32 @to_u32(i8* %17, i32 4, i32 1)
%22 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %21, i32* %22
%23 = call i32 @to_u32(i8* %17, i32 5, i32 2)
%24 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %23, i32* %24
%25 = call i32 @to_u32(i8* %17, i32 7, i32 1)
%26 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %25, i32* %26
%27 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 8
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = mul nsw i32 %29, 10
%31 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 9
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = add nsw i32 %30, -528
%35 = add nsw i32 %34, %33
%36 = mul nsw i32 %35, 10
%37 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 10
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = add nsw i32 %36, -48
%41 = add nsw i32 %40, %39
%42 = mul nsw i32 %41, 10
%43 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 11
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = add nsw i32 %42, -48
%47 = add nsw i32 %46, %45
%48 = getelementptr inbounds i32, i32* %1, i64 4
store i32 %47, i32* %48
br label %49
49: ; preds = %2, %16, %5
ret void
}