#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*/ panic_buffer_overflow();
int make_char(char *to, char from, int length, int ladjust, int max_buf) {
  int i;
  if (length > max_buf) {
    panic_buffer_overflow();
  }
  if (length < 1) {
    length = 1;
  }
  if (ladjust) {
    *to = from;
    for (i = 1; i < length; i++) {
      to[i] = ' ';
    }
  } else {
    for (i = 0; i < length - 1; i++) {
      to[i] = ' ';
    }
    to[length - 1] = from;
  }
  return length;
}


x86 assembly (clang, -O0):
<make_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    113f <make_char+0x2f>
mov    $0x0,%al
call   1030 <panic_buffer_overflow@plt>
cmpl   $0x1,-0x10(%rbp)
jge    1150 <make_char+0x40>
movl   $0x1,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1195 <make_char+0x85>
mov    -0x9(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1190 <make_char+0x80>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <make_char+0x5a>
jmp    11da <make_char+0xca>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c7 <make_char+0xb7>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119c <make_char+0x8c>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_char>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%r14
cmp    %r8d,%edx
jle    113f <make_char+0x1f>
xor    %eax,%eax
call   1030 <panic_buffer_overflow@plt>
test   %ebp,%ebp
mov    $0x1,%ebx
cmovg  %ebp,%ebx
test   %r12d,%r12d
je     1170 <make_char+0x50>
mov    %r15b,(%r14)
cmp    $0x2,%ebp
jl     119a <make_char+0x7a>
add    $0x1,%r14
lea    -0x2(%rbx),%edx
add    $0x1,%rdx
mov    %r14,%rdi
mov    $0x20,%esi
call   1040 <memset@plt>
jmp    119a <make_char+0x7a>
lea    -0x1(%rbx),%r12d
cmp    $0x2,%ebp
jl     1193 <make_char+0x73>
cmp    $0x2,%r12d
mov    $0x1,%edx
cmovge %r12d,%edx
mov    %r14,%rdi
mov    $0x20,%esi
call   1040 <memset@plt>
mov    %r12d,%eax
mov    %r15b,(%r14,%rax,1)
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @make_char(i8* %0, i8 signext %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8 %1, i8* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %8
%13 = load i32, i32* %10
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %5
%16 = call i32 (...) @panic_buffer_overflow()
br label %17
17: ; preds = %15, %5
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 1, i32* %8
br label %21
21: ; preds = %20, %17
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %40
24: ; preds = %21
%25 = load i8, i8* %7
%26 = load i8*, i8** %6
store i8 %25, i8* %26
store i32 1, i32* %11
br label %27
27: ; preds = %36, %24
%28 = load i32, i32* %11
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %39
31: ; preds = %27
%32 = load i8*, i8** %6
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 32, i8* %35
br label %36
36: ; preds = %31
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %27
39: ; preds = %27
br label %61
40: ; preds = %21
store i32 0, i32* %11
br label %41
41: ; preds = %51, %40
%42 = load i32, i32* %11
%43 = load i32, i32* %8
%44 = sub nsw i32 %43, 1
%45 = icmp slt i32 %42, %44
br i1 %45, label %46, label %54
46: ; preds = %41
%47 = load i8*, i8** %6
%48 = load i32, i32* %11
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 32, i8* %50
br label %51
51: ; preds = %46
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 1
store i32 %53, i32* %11
br label %41
54: ; preds = %41
%55 = load i8, i8* %7
%56 = load i8*, i8** %6
%57 = load i32, i32* %8
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
store i8 %55, i8* %60
br label %61
61: ; preds = %54, %39
%62 = load i32, i32* %8
ret i32 %62
}

LLVM IR (-O2):
define i32 @make_char(i8* nocapture writeonly %0, i8 signext %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %2, %4
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 (...) @panic_buffer_overflow()
br label %9
9: ; preds = %7, %5
%10 = icmp sgt i32 %2, 1
%11 = select i1 %10, i32 %2, i32 1
%12 = icmp eq i32 %3, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = add nsw i32 %11, -1
br i1 %10, label %15, label %24
15: ; preds = %13
%16 = call i32 @llvm.smax.i32(i32 %14, i32 1)
%17 = zext i32 %16 to i64
br label %24
18: ; preds = %9
store i8 %1, i8* %0
br i1 %10, label %19, label %27
19: ; preds = %18
%20 = getelementptr i8, i8* %0, i64 1
%21 = add nsw i32 %11, -2
%22 = zext i32 %21 to i64
%23 = add nuw nsw i64 %22, 1
br label %27
24: ; preds = %15, %13
%25 = zext i32 %14 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 %1, i8* %26
br label %27
27: ; preds = %19, %18, %24
ret i32 %11
}