#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 */
struct sprintf_buf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ out(struct sprintf_buf *, char *, int);
void pad(struct sprintf_buf *f, char c, int w, int l, int fl) {
  char pad[256];
  if (fl & ((1U << '-' - ' ') | (1U << '0' - ' ')) || l >= w)
    return;
  l = w - l;
  memset(pad, c, l > sizeof pad ? sizeof pad : l);
  for (; l >= sizeof pad; l -= sizeof pad)
    out(f, pad, sizeof pad);
  out(f, pad, l);
}


x86 assembly (clang, -O0):
<pad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x12000,%eax
cmp    $0x0,%eax
jne    115c <pad+0x3c>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1161 <pad+0x41>
jmp    1215 <pad+0xf5>
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x121(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x100,%rax
jbe    11a2 <pad+0x82>
mov    $0x100,%eax
mov    %rax,-0x138(%rbp)
jmp    11ad <pad+0x8d>
movslq -0x14(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x130(%rbp),%rdi
mov    -0x121(%rbp),%al
mov    -0x138(%rbp),%rcx
mov    %ecx,%edx
movsbl %al,%esi
call   1030 <memset@plt>
movslq -0x14(%rbp),%rax
cmp    $0x100,%rax
jb     1202 <pad+0xe2>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1040 <out@plt>
movslq -0x14(%rbp),%rax
sub    $0x100,%rax
mov    %eax,-0x14(%rbp)
jmp    11cb <pad+0xab>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <out@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pad>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %edx,%ebx
sub    %ecx,%ebx
jle    119b <pad+0x7b>
and    $0x12000,%r8d
jne    119b <pad+0x7b>
mov    %rdi,%r14
cmp    $0x100,%ebx
mov    $0x100,%edx
cmovb  %ebx,%edx
movsbl %sil,%esi
mov    %rsp,%rdi
call   1030 <memset@plt>
cmp    $0x100,%ebx
jb     118e <pad+0x6e>
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x100,%edx
call   1040 <out@plt>
add    $0xffffff00,%ebx
cmp    $0xff,%ebx
ja     1170 <pad+0x50>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1040 <out@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sprintf_buf = type { i32 }
define void @pad(%struct.sprintf_buf* %0, i8 signext %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.sprintf_buf*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i8]
store %struct.sprintf_buf* %0, %struct.sprintf_buf** %6
store i8 %1, i8* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %10
%13 = and i32 %12, 73728
%14 = icmp ne i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %5
%16 = load i32, i32* %9
%17 = load i32, i32* %8
%18 = icmp sge i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15, %5
br label %55
20: ; preds = %15
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = sub nsw i32 %21, %22
store i32 %23, i32* %9
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%25 = load i8, i8* %7
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = icmp ugt i64 %27, 256
br i1 %28, label %29, label %30
29: ; preds = %20
br label %33
30: ; preds = %20
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
br label %33
33: ; preds = %30, %29
%34 = phi i64 [ 256, %29 ], [ %32, %30 ]
%35 = trunc i64 %34 to i32
%36 = call i32 @memset(i8* %24, i8 signext %25, i32 %35)
br label %37
37: ; preds = %45, %33
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = icmp uge i64 %39, 256
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load %struct.sprintf_buf*, %struct.sprintf_buf** %6
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%44 = call i32 @out(%struct.sprintf_buf* %42, i8* %43, i32 256)
br label %45
45: ; preds = %41
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = sub i64 %47, 256
%49 = trunc i64 %48 to i32
store i32 %49, i32* %9
br label %37
50: ; preds = %37
%51 = load %struct.sprintf_buf*, %struct.sprintf_buf** %6
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%53 = load i32, i32* %9
%54 = call i32 @out(%struct.sprintf_buf* %51, i8* %52, i32 %53)
br label %55
55: ; preds = %50, %19
ret void
}

LLVM IR (-O2):
%struct.sprintf_buf = type { i32 }
define void @pad(%struct.sprintf_buf* %0, i8 signext %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = and i32 %4, 73728
%9 = icmp eq i32 %8, 0
%10 = icmp sgt i32 %2, %3
%11 = and i1 %10, %9
br i1 %11, label %12, label %26
12: ; preds = %5
%13 = sub nsw i32 %2, %3
%14 = icmp ult i32 %13, 256
%15 = select i1 %14, i32 %13, i32 256
%16 = call i32 @memset(i8* %7, i8 signext %1, i32 %15)
%17 = icmp ugt i32 %13, 255
br i1 %17, label %18, label %23
18: ; preds = %12, %18
%19 = phi i32 [ %21, %18 ], [ %13, %12 ]
%20 = call i32 @out(%struct.sprintf_buf* %0, i8* %7, i32 256)
%21 = add i32 %19, -256
%22 = icmp ugt i32 %21, 255
br i1 %22, label %18, label %23
23: ; preds = %18, %12
%24 = phi i32 [ %13, %12 ], [ %21, %18 ]
%25 = call i32 @out(%struct.sprintf_buf* %0, i8* %7, i32 %24)
br label %26
26: ; preds = %5, %23
ret void
}