#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*/ strcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *string_front(const char *str, int max) {
  static char buffer[256];
  int length;
  length = strlen(str);
  if (length < max) {
    strcpy(buffer, str);
  } else {
    strncpy(buffer, str, max);
    buffer[max] = 0;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<string_front>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116c <string_front+0x3c>
mov    -0x8(%rbp),%rsi
lea    0x2eee(%rip),%rdi
call   1040 <strcpy@plt>
jmp    118e <string_front+0x5e>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0x2ed6(%rip),%rdi
call   1030 <strncpy@plt>
movslq -0xc(%rbp),%rcx
lea    0x2ec6(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ebb(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_front>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <strlen@plt>
cmp    %ebp,%eax
jge    1153 <string_front+0x23>
lea    0x2f07(%rip),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    116f <string_front+0x3f>
lea    0x2ef6(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rax,%r14,1)
lea    0x2eda(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@string_front.buffer = internal global [256 x i8] zeroinitializer
define i8* @string_front(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @string_front.buffer, i64 0, i64 0), i8* %12)
br label %21
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @string_front.buffer, i64 0, i64 0), i8* %15, i32 %16)
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [256 x i8], [256 x i8]* @string_front.buffer, i64 0, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %14, %11
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @string_front.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@string_front.buffer = internal global [256 x i8] zeroinitializer
define i8* @string_front(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp slt i32 %3, %1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @string_front.buffer, i64 0, i64 0), i8* %0)
br label %11
7: ; preds = %2
%8 = tail call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @string_front.buffer, i64 0, i64 0), i8* %0, i32 %1)
%9 = sext i32 %1 to i64
%10 = getelementptr inbounds [256 x i8], [256 x i8]* @string_front.buffer, i64 0, i64 %9
store i8 0, i8* %10
br label %11
11: ; preds = %7, %5
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @string_front.buffer, i64 0, i64 0)
}