#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*/ memset(char *, char, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
init_field(char *str, const char *val, int maxlen) {
  memset(str, ' ', maxlen + 1);
  if (val) {
    strncpy(str, val, maxlen);
    while (!str[--maxlen])
      str[maxlen] = ' ';
  }
}


x86 assembly (clang, -O0):
<init_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    $0x20,%esi
call   1040 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
je     119e <init_field+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
cmpb   $0x0,(%rax,%rcx,1)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1188 <init_field+0x68>
jmp    1199 <init_field+0x79>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    1162 <init_field+0x42>
jmp    119e <init_field+0x7e>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_field>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x1(%r14),%edx
mov    $0x20,%esi
call   1040 <memset@plt>
test   %r15,%r15
je     116d <init_field+0x4d>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movslq %r14d,%rax
cmpb   $0x0,-0x1(%rax,%rbx,1)
jne    116d <init_field+0x4d>
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
movb   $0x20,(%rax)
cmpb   $0x0,-0x1(%rax)
lea    -0x1(%rax),%rax
je     1160 <init_field+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @init_field(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = load i32, i32* %7
%10 = add nsw i32 %9, 1
%11 = call i32 @memset(i8* %8, i8 signext 32, i32 %10)
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %34
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = call i32 @strncpy(i8* %15, i8* %16, i32 %17)
br label %19
19: ; preds = %28, %14
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = add nsw i32 %21, -1
store i32 %22, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %33
28: ; preds = %19
%29 = load i8*, i8** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 32, i8* %32
br label %19
33: ; preds = %19
br label %34
34: ; preds = %33, %3
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @init_field(i8* %0, i8* %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = tail call i32 @memset(i8* %0, i8 signext 32, i32 %4)
%6 = icmp eq i8* %1, null
br i1 %6, label %21, label %7
7: ; preds = %3
%8 = tail call i32 @strncpy(i8* %0, i8* %1, i32 %2)
%9 = add nsw i32 %2, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %7, %14
%15 = phi i64 [ %17, %14 ], [ %10, %7 ]
%16 = phi i8* [ %18, %14 ], [ %11, %7 ]
store i8 32, i8* %16
%17 = add i64 %15, -1
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %14, label %21
21: ; preds = %14, %7, %3
ret i32 undef
}