#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*/ sprintf(char *, char *, long);
int bin_bcd2(long binary, long *low_res, long *high_res) {
  char number[15], *current;
  int count;
  long *dest;
  *low_res = *high_res = 0;
  sprintf(number, "%014ld", binary);
  for (current = number, count = 13; *current; current++, count--) {
    dest = (count < 7) ? low_res : high_res;
    *dest = *dest << 4;
    *dest |= *current - '0';
  }
  return (0);
}


x86 assembly (clang, -O0):
<bin_bcd2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    -0x27(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xeb7(%rip),%rsi
call   1030 <sprintf@plt>
lea    -0x27(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0xd,-0x34(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d4 <bin_bcd2+0xc4>
cmpl   $0x7,-0x34(%rbp)
jge    1181 <bin_bcd2+0x71>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1189 <bin_bcd2+0x79>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rcx
shl    $0x4,%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
movslq %eax,%rcx
mov    -0x40(%rbp),%rax
or     (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    115d <bin_bcd2+0x4d>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin_bcd2>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rdx
movq   $0x0,(%r14)
movq   $0x0,(%rsi)
lea    0xecb(%rip),%rsi
lea    0x9(%rsp),%rdi
call   1030 <sprintf@plt>
mov    0x9(%rsp),%dl
test   %dl,%dl
je     118d <bin_bcd2+0x7d>
lea    0xa(%rsp),%rax
mov    $0xd,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x7,%ecx
mov    %r14,%rsi
cmovl  %rbx,%rsi
mov    (%rsi),%rdi
shl    $0x4,%rdi
movsbq %dl,%rdx
add    $0xffffffffffffffd0,%rdx
or     %rdi,%rdx
mov    %rdx,(%rsi)
add    $0xffffffff,%ecx
movzbl (%rax),%edx
add    $0x1,%rax
test   %dl,%dl
jne    1160 <bin_bcd2+0x50>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%014ld\00"
define i32 @bin_bcd2(i64 %0, i64* %1, i64* %2) {
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca [15 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64*
store i64 %0, i64* %4
store i64* %1, i64** %5
store i64* %2, i64** %6
%11 = load i64*, i64** %6
store i64 0, i64* %11
%12 = load i64*, i64** %5
store i64 0, i64* %12
%13 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 0
%14 = load i64, i64* %4
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %14)
%16 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 0
store i8* %16, i8** %8
store i32 13, i32* %9
br label %17
17: ; preds = %42, %3
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %47
21: ; preds = %17
%22 = load i32, i32* %9
%23 = icmp slt i32 %22, 7
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i64*, i64** %5
br label %28
26: ; preds = %21
%27 = load i64*, i64** %6
br label %28
28: ; preds = %26, %24
%29 = phi i64* [ %25, %24 ], [ %27, %26 ]
store i64* %29, i64** %10
%30 = load i64*, i64** %10
%31 = load i64, i64* %30
%32 = shl i64 %31, 4
%33 = load i64*, i64** %10
store i64 %32, i64* %33
%34 = load i8*, i8** %8
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = sub nsw i32 %36, 48
%38 = sext i32 %37 to i64
%39 = load i64*, i64** %10
%40 = load i64, i64* %39
%41 = or i64 %40, %38
store i64 %41, i64* %39
br label %42
42: ; preds = %28
%43 = load i8*, i8** %8
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %8
%45 = load i32, i32* %9
%46 = add nsw i32 %45, -1
store i32 %46, i32* %9
br label %17
47: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%014ld\00"
define i32 @bin_bcd2(i64 %0, i64* nocapture %1, i64* nocapture %2) {
%4 = alloca [15 x i8]
%5 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
store i64 0, i64* %2
store i64 0, i64* %1
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %0)
%7 = load i8, i8* %5
%8 = icmp eq i8 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %3, %9
%10 = phi i8 [ %22, %9 ], [ %7, %3 ]
%11 = phi i8* [ %20, %9 ], [ %5, %3 ]
%12 = phi i32 [ %21, %9 ], [ 13, %3 ]
%13 = icmp slt i32 %12, 7
%14 = select i1 %13, i64* %1, i64* %2
%15 = load i64, i64* %14
%16 = shl i64 %15, 4
%17 = sext i8 %10 to i64
%18 = add nsw i64 %17, -48
%19 = or i64 %16, %18
store i64 %19, i64* %14
%20 = getelementptr inbounds i8, i8* %11, i64 1
%21 = add nsw i32 %12, -1
%22 = load i8, i8* %20
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %9
24: ; preds = %9, %3
ret i32 0
}