#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ stderr;
char *str_concat(char *, char *);
char *str_padding_left(char *s, int count) {
  char *_str, *ret;
  if (0 == count) {
    return s;
  }
  _str = (char *)malloc(count + 1);
  if (!_str) {
    fprintf(stderr, "out of memory!\n");
    exit(1);
  }
  memset(_str, ' ', count);
  _str[count] = 0;
  ret = str_concat(_str, s);
  free(_str);
  return ret;
}


x86 assembly (clang, -O0):
<str_padding_left>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    1187 <str_padding_left+0x27>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ff <str_padding_left+0x9f>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c0 <str_padding_left+0x60>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x20,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <str_concat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_padding_left>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %esi,%esi
je     11ad <str_padding_left+0x4d>
mov    %esi,%r15d
lea    0x1(%r15),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b6 <str_padding_left+0x56>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x20,%esi
mov    %r15d,%edx
call   1040 <memset@plt>
movslq %r15d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <str_concat@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"out of memory!\0A\00"
define i8* @str_padding_left(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 0, %8
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i8*, i8** %4
store i8* %11, i8** %3
br label %37
12: ; preds = %2
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %12
%24 = load i8*, i8** %6
%25 = load i32, i32* %5
%26 = call i32 @memset(i8* %24, i8 signext 32, i32 %25)
%27 = load i8*, i8** %6
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %6
%32 = load i8*, i8** %4
%33 = call i8* @str_concat(i8* %31, i8* %32)
store i8* %33, i8** %7
%34 = load i8*, i8** %6
%35 = call i32 @free(i8* %34)
%36 = load i8*, i8** %7
store i8* %36, i8** %3
br label %37
37: ; preds = %23, %10
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"out of memory!\0A\00"
define i8* @str_padding_left(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = add nsw i32 %1, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %4
%14 = tail call i32 @memset(i8* %7, i8 signext 32, i32 %1)
%15 = sext i32 %1 to i64
%16 = getelementptr inbounds i8, i8* %7, i64 %15
store i8 0, i8* %16
%17 = tail call i8* @str_concat(i8* %7, i8* %0)
%18 = tail call i32 @free(i8* %7)
br label %19
19: ; preds = %2, %13
%20 = phi i8* [ %17, %13 ], [ %0, %2 ]
ret i8* %20
}