#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*/ clear_meter(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wt(unsigned int, unsigned int);
int mod_meter(int meter_id, unsigned int kbps) {
  clear_meter(meter_id);
  unsigned int inc, interval;
  unsigned int meter_addr_base;
  unsigned int a, b, temp;
  printf("mod_meter begin!\n");
  printf("rate=%d\n", kbps);
  a = kbps;
  b = 8000 * 125;
  if (a < b) {
    temp = a;
    a = b;
    b = temp;
  }
  while (b != 0) {
    temp = a % b;
    a = b;
    b = temp;
  }
  inc = (unsigned int)(kbps / a);
  interval = (unsigned int)(8000 * 125 / a);
  meter_addr_base = 0x49000000 | (meter_id << 0x08);
  printf("meter_id=%d\n", meter_id);
  printf("interval=%d\n", interval);
  printf("inc=%d\n", inc);
  wt(meter_addr_base, interval);
  wt(meter_addr_base + 4, inc);
  return 0;
}


x86 assembly (clang, -O0):
<mod_meter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <clear_meter@plt>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0xf4240,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1190 <mod_meter+0x60>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1195 <mod_meter+0x65>
cmpl   $0x0,-0x1c(%rbp)
je     11bb <mod_meter+0x8b>
mov    -0x18(%rbp),%eax
xor    %edx,%edx
divl   -0x1c(%rbp)
mov    %edx,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1195 <mod_meter+0x65>
mov    -0x8(%rbp),%eax
xor    %edx,%edx
divl   -0x18(%rbp)
mov    %eax,-0xc(%rbp)
mov    $0xf4240,%eax
xor    %edx,%edx
divl   -0x18(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x8,%eax
or     $0x49000000,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <wt@plt>
mov    -0x14(%rbp),%edi
add    $0x4,%edi
mov    -0xc(%rbp),%esi
call   1050 <wt@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_meter>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %edi,%r14d
call   1040 <clear_meter@plt>
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xf4240,%ebp
mov    $0xf4240,%edx
mov    %ebp,%eax
cmovb  %edx,%eax
cmovb  %ebp,%edx
test   %edx,%edx
je     119e <mod_meter+0x5e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %edx,%ecx
xor    %edx,%edx
div    %ecx
mov    %ecx,%eax
test   %edx,%edx
jne    1190 <mod_meter+0x50>
jmp    11a0 <mod_meter+0x60>
mov    %eax,%ecx
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%r15d
mov    $0xf4240,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%r12d
mov    %r14d,%ebx
shl    $0x8,%ebx
mov    %ebx,%ebp
or     $0x49000000,%ebp
lea    0xe3f(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe37(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %r12d,%esi
call   1060 <wt@plt>
or     $0x49000004,%ebx
mov    %ebx,%edi
mov    %r15d,%esi
call   1060 <wt@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"mod_meter begin!\0A\00"
@.str.1 = [9 x i8] c"rate=%d\0A\00"
@.str.2 = [13 x i8] c"meter_id=%d\0A\00"
@.str.3 = [13 x i8] c"interval=%d\0A\00"
@.str.4 = [8 x i8] c"inc=%d\0A\00"
define i32 @mod_meter(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%11 = load i32, i32* %3
%12 = call i32 @clear_meter(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %4
store i32 %16, i32* %8
store i32 1000000, i32* %9
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* %8
store i32 %21, i32* %10
%22 = load i32, i32* %9
store i32 %22, i32* %8
%23 = load i32, i32* %10
store i32 %23, i32* %9
br label %24
24: ; preds = %20, %2
br label %25
25: ; preds = %28, %24
%26 = load i32, i32* %9
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = urem i32 %29, %30
store i32 %31, i32* %10
%32 = load i32, i32* %9
store i32 %32, i32* %8
%33 = load i32, i32* %10
store i32 %33, i32* %9
br label %25
34: ; preds = %25
%35 = load i32, i32* %4
%36 = load i32, i32* %8
%37 = udiv i32 %35, %36
store i32 %37, i32* %5
%38 = load i32, i32* %8
%39 = udiv i32 1000000, %38
store i32 %39, i32* %6
%40 = load i32, i32* %3
%41 = shl i32 %40, 8
%42 = or i32 1224736768, %41
store i32 %42, i32* %7
%43 = load i32, i32* %3
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %6
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %5
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %7
%50 = load i32, i32* %6
%51 = call i32 @wt(i32 %49, i32 %50)
%52 = load i32, i32* %7
%53 = add i32 %52, 4
%54 = load i32, i32* %5
%55 = call i32 @wt(i32 %53, i32 %54)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"rate=%d\0A\00"
@.str.2 = [13 x i8] c"meter_id=%d\0A\00"
@.str.3 = [13 x i8] c"interval=%d\0A\00"
@.str.4 = [8 x i8] c"inc=%d\0A\00"
@str = [17 x i8] c"mod_meter begin!\00"
define i32 @mod_meter(i32 %0, i32 %1) {
%3 = tail call i32 @clear_meter(i32 %0)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%6 = icmp ult i32 %1, 1000000
%7 = select i1 %6, i32 1000000, i32 %1
%8 = select i1 %6, i32 %1, i32 1000000
%9 = icmp eq i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %2, %10
%11 = phi i32 [ %13, %10 ], [ %8, %2 ]
%12 = phi i32 [ %11, %10 ], [ %7, %2 ]
%13 = urem i32 %12, %11
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %10
15: ; preds = %10, %2
%16 = phi i32 [ %7, %2 ], [ %11, %10 ]
%17 = udiv i32 %1, %16
%18 = udiv i32 1000000, %16
%19 = shl i32 %0, 8
%20 = or i32 %19, 1224736768
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%24 = tail call i32 @wt(i32 %20, i32 %18)
%25 = or i32 %19, 1224736772
%26 = tail call i32 @wt(i32 %25, i32 %17)
ret i32 0
}