#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*/ sprintf(char *, char *, int);
char *PacketSize(int nSize) {
  static char szBuffer[64];
  if ((nSize % 1024) == 0 || (nSize % 1024) == 1023)
    sprintf(szBuffer, "%2dk", (nSize + 512) / 1024);
  else
    sprintf(szBuffer, "%d", nSize);
  return szBuffer;
}


x86 assembly (clang, -O0):
<PacketSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1146 <PacketSize+0x36>
mov    -0x4(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    $0x3ff,%edx
jne    1170 <PacketSize+0x60>
mov    -0x4(%rbp),%eax
add    $0x200,%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0x2ee1(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1186 <PacketSize+0x76>
mov    -0x4(%rbp),%edx
lea    0x2ec6(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2eb3(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PacketSize>:
push   %rax
mov    %edi,%edx
lea    0x3ff(%rdx),%ecx
test   %edi,%edi
cmovns %edi,%ecx
and    $0xfffffc00,%ecx
mov    %edi,%eax
sub    %ecx,%eax
cmp    $0x3ff,%eax
je     1133 <PacketSize+0x23>
test   %eax,%eax
jne    1157 <PacketSize+0x47>
lea    0x200(%rdx),%eax
add    $0x5ff,%edx
test   %eax,%eax
cmovns %eax,%edx
sar    $0xa,%edx
lea    0x2ef2(%rip),%rdi
lea    0xeab(%rip),%rsi
jmp    1165 <PacketSize+0x55>
lea    0x2ee2(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2ecf(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@PacketSize.szBuffer = internal global [64 x i8] zeroinitializer
@.str = [5 x i8] c"%2dk\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @PacketSize(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = srem i32 %3, 1024
%5 = icmp eq i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* %2
%8 = srem i32 %7, 1024
%9 = icmp eq i32 %8, 1023
br i1 %9, label %10, label %15
10: ; preds = %6, %1
%11 = load i32, i32* %2
%12 = add nsw i32 %11, 512
%13 = sdiv i32 %12, 1024
%14 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @PacketSize.szBuffer, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %18
15: ; preds = %6
%16 = load i32, i32* %2
%17 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @PacketSize.szBuffer, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %10
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @PacketSize.szBuffer, i64 0, i64 0)
}

LLVM IR (-O2):
@PacketSize.szBuffer = internal global [64 x i8] zeroinitializer
@.str = [5 x i8] c"%2dk\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @PacketSize(i32 %0) {
%2 = srem i32 %0, 1024
switch i32 %2, label %7 [
i32 0, label %3
i32 1023, label %3
]
3: ; preds = %1, %1
%4 = add nsw i32 %0, 512
%5 = sdiv i32 %4, 1024
%6 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @PacketSize.szBuffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %9
7: ; preds = %1
%8 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @PacketSize.szBuffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %9
9: ; preds = %7, %3
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @PacketSize.szBuffer, i64 0, i64 0)
}