#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 */
scalar_t__ printf(char *, ...);
int data_convert(int input, int length, int *output) {
  int tmp_data;
  tmp_data = input;
  if (length == 2) {
    output[0] = tmp_data / 10;
    output[1] = tmp_data % 10;
  } else if (length == 4) {
    output[0] = tmp_data / 1000;
    tmp_data = tmp_data % 1000;
    output[1] = tmp_data / 100;
    tmp_data = tmp_data % 100;
    output[2] = tmp_data / 10;
    output[3] = tmp_data % 10;
  } else {
    ((void)printf("D/"
                  "venc-file"
                  ": "));
    ((void)printf("(%d) ", 34));
    ((void)printf("error length\n"));
    ((void)printf("\n"));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<data_convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    115c <data_convert+0x4c>
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
mov    %edx,0x4(%rax)
jmp    1222 <data_convert+0x112>
cmpl   $0x4,-0xc(%rbp)
jne    11d4 <data_convert+0xc4>
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
mov    %edx,0xc(%rax)
jmp    121d <data_convert+0x10d>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe25(%rip),%rdi
mov    $0x22,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <data_convert+0x119>
jmp    1222 <data_convert+0x112>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_convert>:
push   %rax
cmp    $0x4,%esi
je     1164 <data_convert+0x34>
cmp    $0x2,%esi
jne    11d0 <data_convert+0xa0>
movslq %edi,%rax
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
mov    %eax,(%rdx)
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %edi,0x4(%rdx)
jmp    11cc <data_convert+0x9c>
movslq %edi,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x26,%rcx
add    %esi,%ecx
mov    %ecx,(%rdx)
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
movswl %ax,%ecx
imul   $0x147b,%ecx,%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
sar    $0x13,%ecx
add    %esi,%ecx
mov    %ecx,0x4(%rdx)
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
movsbl %al,%ecx
imul   $0x67,%ecx,%ecx
movzwl %cx,%ecx
movswl %cx,%esi
shr    $0xf,%ecx
shr    $0xa,%esi
add    %cl,%sil
movsbl %sil,%ecx
mov    %ecx,0x8(%rdx)
movzbl %cl,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %cl,%al
movsbl %al,%eax
mov    %eax,0xc(%rdx)
xor    %eax,%eax
pop    %rcx
ret
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe29(%rip),%rdi
mov    $0x22,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1c(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"D/venc-file: \00"
@.str.1 = [6 x i8] c"(%d) \00"
@.str.2 = [14 x i8] c"error length\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @data_convert(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%9 = load i32, i32* %5
store i32 %9, i32* %8
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = load i32, i32* %8
%14 = sdiv i32 %13, 10
%15 = load i32*, i32** %7
%16 = getelementptr inbounds i32, i32* %15, i64 0
store i32 %14, i32* %16
%17 = load i32, i32* %8
%18 = srem i32 %17, 10
%19 = load i32*, i32** %7
%20 = getelementptr inbounds i32, i32* %19, i64 1
store i32 %18, i32* %20
br label %51
21: ; preds = %3
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 4
br i1 %23, label %24, label %45
24: ; preds = %21
%25 = load i32, i32* %8
%26 = sdiv i32 %25, 1000
%27 = load i32*, i32** %7
%28 = getelementptr inbounds i32, i32* %27, i64 0
store i32 %26, i32* %28
%29 = load i32, i32* %8
%30 = srem i32 %29, 1000
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = sdiv i32 %31, 100
%33 = load i32*, i32** %7
%34 = getelementptr inbounds i32, i32* %33, i64 1
store i32 %32, i32* %34
%35 = load i32, i32* %8
%36 = srem i32 %35, 100
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = sdiv i32 %37, 10
%39 = load i32*, i32** %7
%40 = getelementptr inbounds i32, i32* %39, i64 2
store i32 %38, i32* %40
%41 = load i32, i32* %8
%42 = srem i32 %41, 10
%43 = load i32*, i32** %7
%44 = getelementptr inbounds i32, i32* %43, i64 3
store i32 %42, i32* %44
br label %50
45: ; preds = %21
%46 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%47 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 34)
%48 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%49 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %4
br label %52
50: ; preds = %24
br label %51
51: ; preds = %50, %12
store i32 0, i32* %4
br label %52
52: ; preds = %51, %45
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
@.str = [14 x i8] c"D/venc-file: \00"
@.str.1 = [6 x i8] c"(%d) \00"
@str = [13 x i8] c"error length\00"
define i32 @data_convert(i32 %0, i32 %1, i32* nocapture writeonly %2) {
switch i32 %1, label %23 [
i32 2, label %4
i32 4, label %8
]
4: ; preds = %3
%5 = sdiv i32 %0, 10
store i32 %5, i32* %2
%6 = srem i32 %0, 10
%7 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %6, i32* %7
br label %28
8: ; preds = %3
%9 = sdiv i32 %0, 1000
store i32 %9, i32* %2
%10 = srem i32 %0, 1000
%11 = trunc i32 %10 to i16
%12 = sdiv i16 %11, 100
%13 = sext i16 %12 to i32
%14 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %13, i32* %14
%15 = srem i16 %11, 100
%16 = trunc i16 %15 to i8
%17 = sdiv i8 %16, 10
%18 = sext i8 %17 to i32
%19 = getelementptr inbounds i32, i32* %2, i64 2
store i32 %18, i32* %19
%20 = srem i8 %16, 10
%21 = sext i8 %20 to i32
%22 = getelementptr inbounds i32, i32* %2, i64 3
store i32 %21, i32* %22
br label %28
23: ; preds = %3
%24 = tail call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%25 = tail call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 34)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @putchar(i32 10)
br label %28
28: ; preds = %4, %8, %23
%29 = phi i32 [ -1, %23 ], [ 0, %8 ], [ 0, %4 ]
ret i32 %29
}