#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*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
void leakyBucket(int bucket_size, int output_rate, int packet_size) {
  if (packet_size > bucket_size)
    printf("\nBucket overflow\n");
  else {
    sleep(1);
    while (packet_size > output_rate) {
      printf("\nNo.of bytes output: %d", output_rate);
      packet_size -= output_rate;
      sleep(1);
    }
    printf("\nNo.of bytes output at the end: %d", packet_size);
    printf("\nBucket output successful\n");
  }
}


x86 assembly (clang, -O0):
<leakyBucket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    1150 <leakyBucket+0x30>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b0 <leakyBucket+0x90>
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1191 <leakyBucket+0x71>
mov    -0x8(%rbp),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    $0x1,%edi
call   1040 <sleep@plt>
jmp    115a <leakyBucket+0x3a>
mov    -0xc(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leakyBucket>:
cmp    %edi,%edx
jle    1140 <leakyBucket+0x10>
lea    0xf1a(%rip),%rdi
jmp    1030 <puts@plt>
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
mov    $0x1,%edi
call   1050 <sleep@plt>
cmp    %ebp,%ebx
jle    117c <leakyBucket+0x4c>
lea    0xea3(%rip),%r14
nopl   (%rax)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
sub    %ebp,%ebx
mov    $0x1,%edi
call   1050 <sleep@plt>
cmp    %ebp,%ebx
jg     1160 <leakyBucket+0x30>
lea    0xe95(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"\0ABucket overflow\0A\00"
@.str.1 = [24 x i8] c"\0ANo.of bytes output: %d\00"
@.str.2 = [35 x i8] c"\0ANo.of bytes output at the end: %d\00"
@.str.3 = [27 x i8] c"\0ABucket output successful\0A\00"
define void @leakyBucket(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = load i32, i32* %4
%9 = icmp sgt i32 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %29
12: ; preds = %3
%13 = call i32 @sleep(i32 1)
br label %14
14: ; preds = %18, %12
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i32, i32* %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = sub nsw i32 %22, %21
store i32 %23, i32* %6
%24 = call i32 @sleep(i32 1)
br label %14
25: ; preds = %14
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %25, %10
ret void
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"\0ANo.of bytes output: %d\00"
@.str.2 = [35 x i8] c"\0ANo.of bytes output at the end: %d\00"
@str = [26 x i8] c"\0ABucket output successful\00"
@str.4 = [17 x i8] c"\0ABucket overflow\00"
define void @leakyBucket(i32 %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, %0
br i1 %4, label %17, label %5
5: ; preds = %3
%6 = tail call i32 @sleep(i32 1)
%7 = icmp sgt i32 %2, %1
br i1 %7, label %8, label %14
8: ; preds = %5, %8
%9 = phi i32 [ %11, %8 ], [ %2, %5 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%11 = sub nsw i32 %9, %1
%12 = tail call i32 @sleep(i32 1)
%13 = icmp sgt i32 %11, %1
br i1 %13, label %8, label %14
14: ; preds = %8, %5
%15 = phi i32 [ %2, %5 ], [ %11, %8 ]
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %3, %14
%18 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0), %14 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0), %3 ]
%19 = tail call i32 @puts(i8* dereferenceable(1) %18)
ret void
}