#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 char wchar_t;

/* Variables and functions */
scalar_t__ malloc(int);
int swprintf(char *, int, char *, long);
int /*<<< orphan*/ wcscat(char *, char *);
int /*<<< orphan*/ wcscpy(char *, char *);
wchar_t *complete_long(long int n) {
  int i, strn_len, max_char_len = 10;
  wchar_t strn[50], *zeros;
  zeros = (wchar_t *)malloc(sizeof(wchar_t) * 50);
  wcscpy(zeros, L"");
  wcscpy(strn, L"");
  strn_len = swprintf(strn, 50, L"%ld", n);
  i = 0;
  for (i = 0; i < max_char_len - strn_len; i++) {
    wcscat(zeros, L"0");
  }
  wcscat(zeros, strn);
  return zeros;
}


x86 assembly (clang, -O0):
<complete_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xa,-0x14(%rbp)
mov    $0x32,%edi
call   1060 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1040 <wcscpy@plt>
lea    -0x50(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1040 <wcscpy@plt>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x32,%esi
lea    0xe6b(%rip),%rdx
call   1050 <swprintf@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    11da <complete_long+0x9a>
mov    -0x58(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1030 <wcscat@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ab <complete_long+0x6b>
mov    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <wcscat@plt>
mov    -0x58(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<complete_long>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%r14
mov    $0x32,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xeb1(%rip),%r15
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <wcscpy@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <wcscpy@plt>
lea    0xe7d(%rip),%rdx
mov    %r12,%rdi
mov    $0x32,%esi
mov    %r14,%rcx
call   1050 <swprintf@plt>
cmp    $0x9,%eax
jg     11d0 <complete_long+0x90>
mov    $0xa,%ecx
sub    %eax,%ecx
cmp    $0x2,%ecx
mov    $0x1,%ebp
cmovge %ecx,%ebp
lea    0xe5f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <wcscat@plt>
add    $0xffffffff,%ebp
jne    11c0 <complete_long+0x80>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <wcscat@plt>
mov    %rbx,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i32] zeroinitializer
@.str.1 = [4 x i32] [i32 37, i32 108, i32 100, i32 0]
@.str.2 = [2 x i32] [i32 48, i32 0]
define i8* @complete_long(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [50 x i8]
%7 = alloca i8*
store i64 %0, i64* %2
store i32 10, i32* %5
%8 = call i64 @malloc(i32 50)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = call i32 @wcscpy(i8* %10, i8* bitcast ([1 x i32]* @.str to i8*))
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%13 = call i32 @wcscpy(i8* %12, i8* bitcast ([1 x i32]* @.str to i8*))
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%15 = load i64, i64* %2
%16 = call i32 @swprintf(i8* %14, i32 50, i8* bitcast ([4 x i32]* @.str.1 to i8*), i64 %15)
store i32 %16, i32* %4
store i32 0, i32* %3
store i32 0, i32* %3
br label %17
17: ; preds = %26, %1
%18 = load i32, i32* %3
%19 = load i32, i32* %5
%20 = load i32, i32* %4
%21 = sub nsw i32 %19, %20
%22 = icmp slt i32 %18, %21
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = load i8*, i8** %7
%25 = call i32 @wcscat(i8* %24, i8* bitcast ([2 x i32]* @.str.2 to i8*))
br label %26
26: ; preds = %23
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %17
29: ; preds = %17
%30 = load i8*, i8** %7
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%32 = call i32 @wcscat(i8* %30, i8* %31)
%33 = load i8*, i8** %7
ret i8* %33
}

LLVM IR (-O2):
@.str = [1 x i32] zeroinitializer
@.str.1 = [4 x i32] [i32 37, i32 108, i32 100, i32 0]
@.str.2 = [2 x i32] [i32 48, i32 0]
define i8* @complete_long(i64 %0) {
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @malloc(i32 50)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @wcscpy(i8* %5, i8* bitcast ([1 x i32]* @.str to i8*))
%7 = call i32 @wcscpy(i8* %3, i8* bitcast ([1 x i32]* @.str to i8*))
%8 = call i32 @swprintf(i8* %3, i32 50, i8* bitcast ([4 x i32]* @.str.1 to i8*), i64 %0)
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = sub i32 10, %8
%12 = call i32 @llvm.smax.i32(i32 %11, i32 1)
br label %13
13: ; preds = %10, %13
%14 = phi i32 [ %16, %13 ], [ 0, %10 ]
%15 = call i32 @wcscat(i8* %5, i8* bitcast ([2 x i32]* @.str.2 to i8*))
%16 = add nuw nsw i32 %14, 1
%17 = icmp eq i32 %16, %12
br i1 %17, label %18, label %13
18: ; preds = %13, %1
%19 = call i32 @wcscat(i8* %5, i8* %3)
ret i8* %5
}