#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int read_int_dec_or_hex(char *);
int send_req(int, int, int, int);
int /*<<< orphan*/ stderr;
int u_set_pps(int fd, char **argv) {
  uint32_t pps;
  int len;
  pps = read_int_dec_or_hex(argv[0]);
  len = ({ (send_req(fd, 0x04, -1, 0) & 0xffff) + 20; });
  if (pps * len * 8 >= 100000000) {
    fprintf(stderr,
            "ERROR: "
            "Overload, this is only 100Mbps Ethernet... %d\n",
            pps * len * 8);
    return 1;
  }
  send_req(fd, 0x08, 100000000 / pps, 1);
  return 0;
}


x86 assembly (clang, -O0):
<u_set_pps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <read_int_dec_or_hex@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1030 <send_req@plt>
and    $0xffff,%eax
add    $0x14,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
shl    $0x3,%eax
cmp    $0x5f5e100,%eax
jl     11b3 <u_set_pps+0x83>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
imul   -0x18(%rbp),%edx
shl    $0x3,%edx
lea    0xe5e(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <u_set_pps+0xa7>
mov    -0x8(%rbp),%edi
mov    $0x5f5e100,%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%edx
mov    $0x8,%esi
mov    $0x1,%ecx
call   1030 <send_req@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u_set_pps>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    (%rsi),%rdi
call   1050 <read_int_dec_or_hex@plt>
mov    %eax,%ebx
xor    %r14d,%r14d
mov    %ebp,%edi
mov    $0x4,%esi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1030 <send_req@plt>
movzwl %ax,%edx
add    $0x14,%edx
imul   %ebx,%edx
cmp    $0xbebc20,%edx
jl     1187 <u_set_pps+0x57>
shl    $0x3,%edx
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%r14d
jmp    11a3 <u_set_pps+0x73>
mov    $0x5f5e100,%eax
xor    %edx,%edx
idiv   %ebx
mov    %ebp,%edi
mov    $0x8,%esi
mov    %eax,%edx
mov    $0x1,%ecx
call   1030 <send_req@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [54 x i8] c"ERROR: Overload, this is only 100Mbps Ethernet... %d\0A\00"
define i32 @u_set_pps(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 @read_int_dec_or_hex(i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %4
%14 = call i32 @send_req(i32 %13, i32 4, i32 -1, i32 0)
%15 = and i32 %14, 65535
%16 = add nsw i32 %15, 20
store i32 %16, i32* %8
%17 = load i32, i32* %8
store i32 %17, i32* %7
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = mul nsw i32 %18, %19
%21 = mul nsw i32 %20, 8
%22 = icmp sge i32 %21, 100000000
br i1 %22, label %23, label %30
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = mul nsw i32 %25, %26
%28 = mul nsw i32 %27, 8
%29 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %28)
store i32 1, i32* %3
br label %35
30: ; preds = %2
%31 = load i32, i32* %4
%32 = load i32, i32* %6
%33 = sdiv i32 100000000, %32
%34 = call i32 @send_req(i32 %31, i32 8, i32 %33, i32 1)
store i32 0, i32* %3
br label %35
35: ; preds = %30, %23
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [54 x i8] c"ERROR: Overload, this is only 100Mbps Ethernet... %d\0A\00"
define i32 @u_set_pps(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @read_int_dec_or_hex(i8* %3)
%5 = tail call i32 @send_req(i32 %0, i32 4, i32 -1, i32 0)
%6 = and i32 %5, 65535
%7 = add nuw nsw i32 %6, 20
%8 = mul nsw i32 %7, %4
%9 = icmp sgt i32 %8, 12499999
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = shl nsw i32 %8, 3
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %17
14: ; preds = %2
%15 = sdiv i32 100000000, %4
%16 = tail call i32 @send_req(i32 %0, i32 8, i32 %15, i32 1)
br label %17
17: ; preds = %14, %10
%18 = phi i32 [ 1, %10 ], [ 0, %14 ]
ret i32 %18
}