#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*/ printf(char *, ...);
int psvec(unsigned short v, int len) {
  int i;
  printf("->");
  for (i = len - 1; i >= 0; i--) {
    printf("%d", (int)((v >> i) & (unsigned long long)1));
  }
  printf("<-\n");
  return 0;
}


x86 assembly (clang, -O0):
<psvec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1170 <psvec+0x60>
movzwl -0x2(%rbp),%eax
mov    -0xc(%rbp),%ecx
sar    %cl,%eax
cltq
and    $0x1,%rax
mov    %eax,%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <psvec+0x29>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psvec>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xed1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jle    116c <psvec+0x4c>
movzwl %bp,%ebp
add    $0x1,%ebx
lea    0xebc(%rip),%r14
nopw   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%ecx
mov    %ebp,%esi
shr    %cl,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1150 <psvec+0x30>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"->\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"<-\0A\00"
define i32 @psvec(i16 zeroext %0, i32 %1) {
%3 = alloca i16
%4 = alloca i32
%5 = alloca i32
store i16 %0, i16* %3
store i32 %1, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %4
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %5
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %5
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = load i16, i16* %3
%14 = zext i16 %13 to i32
%15 = load i32, i32* %5
%16 = ashr i32 %14, %15
%17 = sext i32 %16 to i64
%18 = and i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %12
%22 = load i32, i32* %5
%23 = add nsw i32 %22, -1
store i32 %23, i32* %5
br label %9
24: ; preds = %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"->\00"
@.str.1 = [3 x i8] c"%d\00"
@str = [3 x i8] c"<-\00"
define i32 @psvec(i16 zeroext %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = zext i16 %0 to i32
br label %7
7: ; preds = %5, %7
%8 = phi i32 [ %1, %5 ], [ %9, %7 ]
%9 = add nsw i32 %8, -1
%10 = lshr i32 %6, %9
%11 = and i32 %10, 1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = icmp ugt i32 %8, 1
br i1 %13, label %7, label %14
14: ; preds = %7, %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
ret i32 0
}