#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*/ right(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strinit(char *, int, int /*<<< orphan*/);
int strlen(char *);
char *justify(char *target, char *source, int tmax) {
  int slen;
  slen = strlen(source);
  if (slen >= tmax)
    right(target, source, tmax);
  else {
    strinit(target, tmax - slen, '0');
    strcat(target, source);
  }
  return target;
}


x86 assembly (clang, -O0):
<justify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1180 <justify+0x40>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <right@plt>
jmp    11a1 <justify+0x61>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    -0x18(%rbp),%esi
mov    $0x30,%edx
call   1060 <strinit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<justify>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jge    1176 <justify+0x36>
sub    %eax,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x30,%edx
call   1060 <strinit@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
jmp    1183 <justify+0x43>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <right@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @justify(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = call i32 @right(i8* %14, i8* %15, i32 %16)
br label %27
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = sub nsw i32 %20, %21
%23 = call i32 @strinit(i8* %19, i32 %22, i32 48)
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = call i32 @strcat(i8* %24, i8* %25)
br label %27
27: ; preds = %18, %13
%28 = load i8*, i8** %4
ret i8* %28
}

LLVM IR (-O2):
define i8* @justify(i8* returned %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp slt i32 %4, %2
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @right(i8* %0, i8* %1, i32 %2)
br label %12
8: ; preds = %3
%9 = sub nsw i32 %2, %4
%10 = tail call i32 @strinit(i8* %0, i32 %9, i32 48)
%11 = tail call i32 @strcat(i8* %0, i8* %1)
br label %12
12: ; preds = %8, %6
ret i8* %0
}