#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
char *format_rate(int rate) {
  static char buf[14];
  if (rate <= 0)
    snprintf(buf, sizeof(buf), "unknown");
  else
    snprintf(buf, sizeof(buf), "%d.%d MBit/s", rate / 1000,
             (rate % 1000) / 100);
  return buf;
}


x86 assembly (clang, -O0):
<format_rate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1144 <format_rate+0x34>
lea    0x2efd(%rip),%rdi
mov    $0xe,%esi
lea    0xec8(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1183 <format_rate+0x73>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x4(%rbp),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    %edx,%eax
mov    $0x64,%esi
cltd
idiv   %esi
mov    %eax,%r8d
lea    0x2eb9(%rip),%rdi
mov    $0xe,%esi
lea    0xe8c(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    0x2e9f(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_rate>:
push   %rax
test   %edi,%edi
jle    1157 <format_rate+0x47>
mov    %edi,%eax
imul   $0x10624dd3,%rax,%rcx
shr    $0x26,%rcx
imul   $0x3e8,%ecx,%eax
sub    %eax,%edi
movzwl %di,%eax
shr    $0x2,%eax
imul   $0x147b,%eax,%r8d
shr    $0x11,%r8d
lea    0x2ee7(%rip),%rdi
lea    0xebf(%rip),%rdx
mov    $0xe,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    1171 <format_rate+0x61>
lea    0x2ecb(%rip),%rdi
lea    0xe9b(%rip),%rdx
mov    $0xe,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0x2eb1(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@format_rate.buf = internal global [14 x i8] zeroinitializer
@.str = [8 x i8] c"unknown\00"
@.str.1 = [13 x i8] c"%d.%d MBit/s\00"
define i8* @format_rate(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp sle i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @format_rate.buf, i64 0, i64 0), i32 14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %14
7: ; preds = %1
%8 = load i32, i32* %2
%9 = sdiv i32 %8, 1000
%10 = load i32, i32* %2
%11 = srem i32 %10, 1000
%12 = sdiv i32 %11, 100
%13 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @format_rate.buf, i64 0, i64 0), i32 14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %12)
br label %14
14: ; preds = %7, %5
ret i8* getelementptr inbounds ([14 x i8], [14 x i8]* @format_rate.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@format_rate.buf = internal global [14 x i8] zeroinitializer
@.str = [8 x i8] c"unknown\00"
@.str.1 = [13 x i8] c"%d.%d MBit/s\00"
define i8* @format_rate(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @format_rate.buf, i64 0, i64 0), i32 14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %12
5: ; preds = %1
%6 = udiv i32 %0, 1000
%7 = urem i32 %0, 1000
%8 = trunc i32 %7 to i16
%9 = udiv i16 %8, 100
%10 = zext i16 %9 to i32
%11 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @format_rate.buf, i64 0, i64 0), i32 14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %10)
br label %12
12: ; preds = %5, %3
ret i8* getelementptr inbounds ([14 x i8], [14 x i8]* @format_rate.buf, i64 0, i64 0)
}