#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 ceil(float);
int /*<<< orphan*/ do_iptables_cmd(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
void fw_add_limit_speed(char *ip, float speed) {
  char cmd[512];
  int real_speed;
  float rate = 1.5;
  real_speed = ceil(speed / rate);
  sprintf(cmd, "-t mangle -I FW_LIMIT_SPEED -d %s -j DROP", ip);
  do_iptables_cmd(cmd);
  sprintf(cmd,
          "-t mangle -I FW_LIMIT_SPEED -d %s -m limit --limit %d/sec "
          "--limit-burst %d -j ACCEPT",
          ip, real_speed, real_speed);
  do_iptables_cmd(cmd);
}


x86 assembly (clang, -O0):
<fw_add_limit_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  0xeb4(%rip),%xmm0
movss  %xmm0,-0x218(%rbp)
ff
movss  -0xc(%rbp),%xmm0
divss  -0x218(%rbp),%xmm0
ff
call   1030 <ceil@plt>
mov    %eax,-0x214(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x210(%rbp),%rdi
call   1040 <do_iptables_cmd@plt>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x214(%rbp),%ecx
mov    -0x214(%rbp),%r8d
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x210(%rbp),%rdi
call   1040 <do_iptables_cmd@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fw_add_limit_speed>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rbx
divss  0xeba(%rip),%xmm0
call   1030 <ceil@plt>
mov    %eax,%ebp
lea    0xeb0(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1040 <do_iptables_cmd@plt>
lea    0xebb(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1040 <do_iptables_cmd@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"-t mangle -I FW_LIMIT_SPEED -d %s -j DROP\00"
@.str.1 = [85 x i8] c"-t mangle -I FW_LIMIT_SPEED -d %s -m limit --limit %d/sec --limit-burst %d -j ACCEPT\00"
define void @fw_add_limit_speed(i8* %0, float %1) {
%3 = alloca i8*
%4 = alloca float
%5 = alloca [512 x i8]
%6 = alloca i32
%7 = alloca float
store i8* %0, i8** %3
store float %1, float* %4
store float 1.500000e+00, float* %7
%8 = load float, float* %4
%9 = load float, float* %7
%10 = fdiv float %8, %9
%11 = call i32 @ceil(float %10)
store i32 %11, i32* %6
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%16 = call i32 @do_iptables_cmd(i8* %15)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%18 = load i8*, i8** %3
%19 = load i32, i32* %6
%20 = load i32, i32* %6
%21 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %19, i32 %20)
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%23 = call i32 @do_iptables_cmd(i8* %22)
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"-t mangle -I FW_LIMIT_SPEED -d %s -j DROP\00"
@.str.1 = [85 x i8] c"-t mangle -I FW_LIMIT_SPEED -d %s -m limit --limit %d/sec --limit-burst %d -j ACCEPT\00"
define void @fw_add_limit_speed(i8* %0, float %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = fdiv float %1, 1.500000e+00
%6 = tail call i32 @ceil(float %5)
%7 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i32 @do_iptables_cmd(i8* %4)
%9 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %6, i32 %6)
%10 = call i32 @do_iptables_cmd(i8* %4)
ret void
}