#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 execute(char *, char const *, ...);
int tc_attach_upload_qdisc(const char dev[], const char ifb_dev[],
                           int upload_limit) {
  int rc = 0;
  execute("tc qdisc del dev %s root", ifb_dev);
  execute("tc qdisc del dev %s ingress", dev);
  rc |= execute("tc qdisc add dev %s root handle 1: hfsc default 2", ifb_dev);
  rc |= execute("tc class add dev %s parent 1: classid 1:1 hfsc sc rate %dkbit "
                "ul rate %dkbit",
                ifb_dev, upload_limit, upload_limit);
  rc |= execute("tc class add dev %s parent 1:1 classid 1:2 hfsc sc rate "
                "%dkbit ul rate %dkbit",
                ifb_dev, upload_limit / 10, upload_limit / 10);
  rc |= execute("tc qdisc add dev %s ingress", dev);
  rc |= execute(
      "tc filter add dev %s parent ffff: protocol ip prio 1 u32 match u32 0 0 "
      "flowid 1:1 action connmark action mirred egress redirect dev %s",
      dev, ifb_dev);
  return rc;
}


x86 assembly (clang, -O0):
<tc_attach_upload_qdisc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <execute@plt>
mov    -0x8(%rbp),%rsi
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <execute@plt>
mov    -0x10(%rbp),%rsi
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <execute@plt>
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xef0(%rip),%rdi
mov    $0x0,%al
call   1030 <execute@plt>
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    0xf07(%rip),%rdi
mov    $0x0,%al
call   1030 <execute@plt>
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xf3d(%rip),%rdi
mov    $0x0,%al
call   1030 <execute@plt>
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xf3d(%rip),%rdi
mov    $0x0,%al
call   1030 <execute@plt>
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tc_attach_upload_qdisc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xed9(%rip),%rdi
xor    %eax,%eax
call   1030 <execute@plt>
lea    0xee4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <execute@plt>
lea    0xeef(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <execute@plt>
mov    %eax,%r12d
lea    0xf0d(%rip),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <execute@plt>
mov    %eax,%ebx
or     %r12d,%ebx
movslq %ebp,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x22,%rcx
add    %eax,%ecx
lea    0xf29(%rip),%rdi
mov    %r15,%rsi
mov    %ecx,%edx
xor    %eax,%eax
call   1030 <execute@plt>
mov    %eax,%r12d
lea    0xf61(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <execute@plt>
mov    %eax,%ebp
or     %ebx,%ebp
lea    0xf68(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <execute@plt>
or     %ebp,%eax
or     %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"tc qdisc del dev %s root\00"
@.str.1 = [28 x i8] c"tc qdisc del dev %s ingress\00"
@.str.2 = [50 x i8] c"tc qdisc add dev %s root handle 1: hfsc default 2\00"
@.str.3 = [77 x i8] c"tc class add dev %s parent 1: classid 1:1 hfsc sc rate %dkbit ul rate %dkbit\00"
@.str.4 = [78 x i8] c"tc class add dev %s parent 1:1 classid 1:2 hfsc sc rate %dkbit ul rate %dkbit\00"
@.str.5 = [28 x i8] c"tc qdisc add dev %s ingress\00"
@.str.6 = [135 x i8] c"tc filter add dev %s parent ffff: protocol ip prio 1 u32 match u32 0 0 flowid 1:1 action connmark action mirred egress redirect dev %s\00"
define i32 @tc_attach_upload_qdisc(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %4
%11 = call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %5
%13 = call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i32, i32* %7
%15 = or i32 %14, %13
store i32 %15, i32* %7
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = load i32, i32* %6
%19 = call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.3, i64 0, i64 0), i8* %16, i32 %17, i32 %18)
%20 = load i32, i32* %7
%21 = or i32 %20, %19
store i32 %21, i32* %7
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = sdiv i32 %23, 10
%25 = load i32, i32* %6
%26 = sdiv i32 %25, 10
%27 = call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.4, i64 0, i64 0), i8* %22, i32 %24, i32 %26)
%28 = load i32, i32* %7
%29 = or i32 %28, %27
store i32 %29, i32* %7
%30 = load i8*, i8** %4
%31 = call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %7
%33 = or i32 %32, %31
store i32 %33, i32* %7
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.6, i64 0, i64 0), i8* %34, i8* %35)
%37 = load i32, i32* %7
%38 = or i32 %37, %36
store i32 %38, i32* %7
%39 = load i32, i32* %7
ret i32 %39
}

LLVM IR (-O2):
@.str = [25 x i8] c"tc qdisc del dev %s root\00"
@.str.1 = [28 x i8] c"tc qdisc del dev %s ingress\00"
@.str.2 = [50 x i8] c"tc qdisc add dev %s root handle 1: hfsc default 2\00"
@.str.3 = [77 x i8] c"tc class add dev %s parent 1: classid 1:1 hfsc sc rate %dkbit ul rate %dkbit\00"
@.str.4 = [78 x i8] c"tc class add dev %s parent 1:1 classid 1:2 hfsc sc rate %dkbit ul rate %dkbit\00"
@.str.5 = [28 x i8] c"tc qdisc add dev %s ingress\00"
@.str.6 = [135 x i8] c"tc filter add dev %s parent ffff: protocol ip prio 1 u32 match u32 0 0 flowid 1:1 action connmark action mirred egress redirect dev %s\00"
define i32 @tc_attach_upload_qdisc(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1)
%5 = tail call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%6 = tail call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%7 = tail call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %2, i32 %2)
%8 = or i32 %7, %6
%9 = sdiv i32 %2, 10
%10 = tail call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.4, i64 0, i64 0), i8* %1, i32 %9, i32 %9)
%11 = or i32 %8, %10
%12 = tail call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%13 = or i32 %11, %12
%14 = tail call i32 (i8*, i8*, ...) @execute(i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.6, i64 0, i64 0), i8* %0, i8* %1)
%15 = or i32 %13, %14
ret i32 %15
}