#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*/ leakyBucket(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sleep(int);
int main() {
  int bucket_size, output_rate, packets, packet_size, delay;
  int i;
  printf("Enter bucket size: ");
  scanf("%d", &bucket_size);
  printf("Enter output rate: ");
  scanf("%d", &output_rate);
  printf("Enter no.of packets: ");
  scanf("%d", &packets);
  for (i = 0; i < packets; i++) {
    delay = rand() % 10;
    sleep(delay);
    packet_size = rand() % 1000;
    printf("\nPacket no. %d size is %d\n", i + 1, packet_size);
    leakyBucket(bucket_size, output_rate, packet_size);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe82(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe64(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    122b <main+0xdb>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x14(%rbp),%edx
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <leakyBucket@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c0 <main+0x70>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea7(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    1236 <main+0xe6>
lea    0xe83(%rip),%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rbx
imul   $0x10624dd3,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%ebx
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    %ebx,%edx
call   1050 <leakyBucket@plt>
cmp    0x4(%rsp),%ebp
jl     11c0 <main+0x70>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter bucket size: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Enter output rate: \00"
@.str.3 = [22 x i8] c"Enter no.of packets: \00"
@.str.4 = [27 x i8] c"\0APacket no. %d size is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
store i32 0, i32* %7
br label %14
14: ; preds = %33, %0
%15 = load i32, i32* %7
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 10
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = call i32 @sleep(i32 %21)
%23 = call i32 (...) @rand()
%24 = srem i32 %23, 1000
store i32 %24, i32* %5
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
%27 = load i32, i32* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %26, i32 %27)
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = load i32, i32* %5
%32 = call i32 @leakyBucket(i32 %29, i32 %30, i32 %31)
br label %33
33: ; preds = %18
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %14
36: ; preds = %14
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter bucket size: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Enter output rate: \00"
@.str.3 = [22 x i8] c"Enter no.of packets: \00"
@.str.4 = [27 x i8] c"\0APacket no. %d size is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %0, %15
%16 = phi i32 [ %22, %15 ], [ 0, %0 ]
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 10
%19 = call i32 @sleep(i32 %18)
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 1000
%22 = add nuw nsw i32 %16, 1
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %22, i32 %21)
%24 = load i32, i32* %1
%25 = load i32, i32* %2
%26 = call i32 @leakyBucket(i32 %24, i32 %25, i32 %21)
%27 = load i32, i32* %3
%28 = icmp slt i32 %22, %27
br i1 %28, label %15, label %29
29: ; preds = %15, %0
ret i32 0
}