#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ putc(unsigned char, int /*<<< orphan*/ *);
void print_repeat(FILE *f, int num, char up, char down) {
  unsigned char ch = num < 0 ? down : up;
  signed char dir = num < 0 ? 1 : -1;
  while (num != 0) {
    putc(ch, f);
    num += dir;
  }
}


x86 assembly (clang, -O0):
<print_repeat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %cl,-0xd(%rbp)
mov    %al,-0xe(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    113f <print_repeat+0x2f>
movsbl -0xe(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <print_repeat+0x36>
movsbl -0xd(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0xf(%rbp)
mov    -0xc(%rbp),%edx
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %al,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     118a <print_repeat+0x7a>
mov    -0xf(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
movsbl -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1162 <print_repeat+0x52>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_repeat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
cmovs  %ecx,%edx
je     114f <print_repeat+0x3f>
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%eax
shr    $0x1f,%eax
lea    (%rax,%rax,1),%r15d
add    $0xffffffff,%r15d
movzbl %dl,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
add    %r15d,%ebx
jne    1140 <print_repeat+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @print_repeat(i32* %0, i32 %1, i8 signext %2, i8 signext %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8 %2, i8* %7
store i8 %3, i8* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i8, i8* %8
%15 = sext i8 %14 to i32
br label %19
16: ; preds = %4
%17 = load i8, i8* %7
%18 = sext i8 %17 to i32
br label %19
19: ; preds = %16, %13
%20 = phi i32 [ %15, %13 ], [ %18, %16 ]
%21 = trunc i32 %20 to i8
store i8 %21, i8* %9
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 1, i32 -1
%26 = trunc i32 %25 to i8
store i8 %26, i8* %10
br label %27
27: ; preds = %30, %19
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i8, i8* %9
%32 = load i32*, i32** %5
%33 = call i32 @putc(i8 zeroext %31, i32* %32)
%34 = load i8, i8* %10
%35 = sext i8 %34 to i32
%36 = load i32, i32* %6
%37 = add nsw i32 %36, %35
store i32 %37, i32* %6
br label %27
38: ; preds = %27
ret void
}

LLVM IR (-O2):
define void @print_repeat(i32* nocapture %0, i32 %1, i8 signext %2, i8 signext %3) {
%5 = icmp slt i32 %1, 0
%6 = select i1 %5, i8 %3, i8 %2
%7 = icmp eq i32 %1, 0
br i1 %7, label %15, label %8
8: ; preds = %4
%9 = select i1 %5, i32 1, i32 -1
br label %10
10: ; preds = %8, %10
%11 = phi i32 [ %1, %8 ], [ %13, %10 ]
%12 = tail call i32 @putc(i8 zeroext %6, i32* %0)
%13 = add nsw i32 %11, %9
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %10
15: ; preds = %10, %4
ret void
}