#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 */
long RLIM_INFINITY;
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *sprintrlim(long lim) {
  static char buf[32];
  if (lim == RLIM_INFINITY)
    sprintf(buf, "RLIM_INFINITY");
  else if (lim > 1024 && lim % 1024 == 0)
    sprintf(buf, "%ld*1024", lim / 1024);
  else
    sprintf(buf, "%ld", lim);
  return buf;
}


x86 assembly (clang, -O0):
<sprintrlim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2eb9(%rip),%rcx
cmp    (%rcx),%rax
jne    114a <sprintrlim+0x3a>
lea    0x2f09(%rip),%rdi
lea    0xec2(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11b9 <sprintrlim+0xa9>
cmpq   $0x400,-0x8(%rbp)
jle    119b <sprintrlim+0x8b>
mov    -0x8(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    119b <sprintrlim+0x8b>
mov    -0x8(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
lea    0x2eb8(%rip),%rdi
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11b4 <sprintrlim+0xa4>
mov    -0x8(%rbp),%rdx
lea    0x2e9a(%rip),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11b9 <sprintrlim+0xa9>
lea    0x2e80(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprintrlim>:
push   %rax
mov    0x2ec8(%rip),%rax
cmp    %rdi,(%rax)
jne    1141 <sprintrlim+0x31>
movabs $0x5954494e49464e,%rax
mov    %rax,0x2f18(%rip)
movabs $0x464e495f4d494c52,%rax
49 4e 46
mov    %rax,0x2f01(%rip)
jmp    1182 <sprintrlim+0x72>
mov    %rdi,%rdx
cmp    $0x401,%rdi
jl     116d <sprintrlim+0x5d>
mov    %edx,%eax
and    $0x3ff,%eax
test   %rax,%rax
jne    116d <sprintrlim+0x5d>
shr    $0xa,%rdx
lea    0x2edc(%rip),%rdi
lea    0xea3(%rip),%rsi
jmp    117b <sprintrlim+0x6b>
lea    0x2ecc(%rip),%rdi
lea    0xe9c(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
lea    0x2eb7(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@sprintrlim.buf = internal global [32 x i8] zeroinitializer
@RLIM_INFINITY = global i64 0
@.str = [14 x i8] c"RLIM_INFINITY\00"
@.str.1 = [9 x i8] c"%ld*1024\00"
@.str.2 = [4 x i8] c"%ld\00"
define i8* @sprintrlim(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = load i64, i64* @RLIM_INFINITY
%5 = icmp eq i64 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @sprintrlim.buf, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %23
8: ; preds = %1
%9 = load i64, i64* %2
%10 = icmp sgt i64 %9, 1024
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i64, i64* %2
%13 = srem i64 %12, 1024
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i64, i64* %2
%17 = sdiv i64 %16, 1024
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @sprintrlim.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %17)
br label %22
19: ; preds = %11, %8
%20 = load i64, i64* %2
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @sprintrlim.buf, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %20)
br label %22
22: ; preds = %19, %15
br label %23
23: ; preds = %22, %6
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @sprintrlim.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@sprintrlim.buf = internal global [32 x i8] zeroinitializer
@RLIM_INFINITY = global i64 0
@.str = [14 x i8] c"RLIM_INFINITY\00"
@.str.1 = [9 x i8] c"%ld*1024\00"
@.str.2 = [4 x i8] c"%ld\00"
define i8* @sprintrlim(i64 %0) {
%2 = load i64, i64* @RLIM_INFINITY
%3 = icmp eq i64 %2, %0
br i1 %3, label %4, label %5
4: ; preds = %1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(14) getelementptr inbounds ([32 x i8], [32 x i8]* @sprintrlim.buf, i64 0, i64 0), i8* align 1 dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 14, i1 false)
br label %15
5: ; preds = %1
%6 = icmp sgt i64 %0, 1024
%7 = and i64 %0, 1023
%8 = icmp eq i64 %7, 0
%9 = and i1 %6, %8
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = lshr i64 %0, 10
%12 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @sprintrlim.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %11)
br label %15
13: ; preds = %5
%14 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @sprintrlim.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %0)
br label %15
15: ; preds = %10, %13, %4
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @sprintrlim.buf, i64 0, i64 0)
}