#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*/ SLsmg_write_nchars(char *, int);
int strlen(char *);
void SLsmg_write_nstring(char *str, int n) {
  int width;
  char blank = ' ';
  if (str == NULL)
    width = 0;
  else {
    width = strlen(str);
    if (width > n)
      width = n;
    SLsmg_write_nchars(str, width);
  }
  while (width++ < n)
    SLsmg_write_nchars(&blank, 1);
}


x86 assembly (clang, -O0):
<SLsmg_write_nstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x20,-0x11(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114a <SLsmg_write_nstring+0x2a>
movl   $0x0,-0x10(%rbp)
jmp    1174 <SLsmg_write_nstring+0x54>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1168 <SLsmg_write_nstring+0x48>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <SLsmg_write_nchars@plt>
jmp    1179 <SLsmg_write_nstring+0x59>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
cmp    -0xc(%rbp),%eax
jge    11a0 <SLsmg_write_nstring+0x80>
lea    -0x11(%rbp),%rdi
mov    $0x1,%esi
call   1040 <SLsmg_write_nchars@plt>
jmp    1179 <SLsmg_write_nstring+0x59>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SLsmg_write_nstring>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
movb   $0x20,0xf(%rsp)
test   %rdi,%rdi
je     1153 <SLsmg_write_nstring+0x33>
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%ebp
cmp    %ebx,%eax
cmovg  %ebx,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <SLsmg_write_nchars@plt>
cmp    %ebx,%ebp
jl     1159 <SLsmg_write_nstring+0x39>
jmp    1172 <SLsmg_write_nstring+0x52>
xor    %ebp,%ebp
cmp    %ebx,%ebp
jge    1172 <SLsmg_write_nstring+0x52>
sub    %ebp,%ebx
lea    0xf(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
call   1040 <SLsmg_write_nchars@plt>
add    $0xffffffff,%ebx
jne    1160 <SLsmg_write_nstring+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @SLsmg_write_nstring(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 32, i8* %6
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %5
br label %22
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp sgt i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = load i32, i32* %4
store i32 %17, i32* %5
br label %18
18: ; preds = %16, %10
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = call i32 @SLsmg_write_nchars(i8* %19, i32 %20)
br label %22
22: ; preds = %18, %9
br label %23
23: ; preds = %28, %22
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
%26 = load i32, i32* %4
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @SLsmg_write_nchars(i8* %6, i32 1)
br label %23
30: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @SLsmg_write_nstring(i8* %0, i32 %1) {
%3 = alloca i8
store i8 32, i8* %3
%4 = icmp eq i8* %0, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, %1
%8 = select i1 %7, i32 %1, i32 %6
%9 = tail call i32 @SLsmg_write_nchars(i8* %0, i32 %8)
br label %10
10: ; preds = %2, %5
%11 = phi i32 [ %8, %5 ], [ 0, %2 ]
%12 = icmp slt i32 %11, %1
br i1 %12, label %13, label %18
13: ; preds = %10, %13
%14 = phi i32 [ %15, %13 ], [ %11, %10 ]
%15 = add i32 %14, 1
%16 = call i32 @SLsmg_write_nchars(i8* %3, i32 1)
%17 = icmp eq i32 %15, %1
br i1 %17, label %18, label %13
18: ; preds = %13, %10
ret void
}