#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 read_int_dec_or_hex(char *);
int send_req(int, int, int, int);
int /*<<< orphan*/ stderr;
int u_set_mbps(int fd, char **argv) {
  uint32_t mbps;
  int len;
  mbps = read_int_dec_or_hex(argv[0]);
  if (mbps > 100) {
    fprintf(stderr, "ERROR: "
                    "Overload, this is only 100Mbps Ethernet...\n");
    return 1;
  }
  len = ({ (send_req(fd, 0x04, -1, 0) & 0xffff) + 20; });
  send_req(fd, 0x08, 800 * len / mbps, 1);
  return 0;
}


x86 assembly (clang, -O0):
<u_set_mbps>:
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)
cmpl   $0x64,-0x14(%rbp)
jle    1179 <u_set_mbps+0x49>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c4 <u_set_mbps+0x94>
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    -0x8(%rbp),%edi
imul   $0x320,-0x18(%rbp),%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_mbps>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    (%rsi),%rdi
call   1050 <read_int_dec_or_hex@plt>
cmp    $0x65,%eax
jl     1160 <u_set_mbps+0x30>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%ebp
jmp    119e <u_set_mbps+0x6e>
mov    %eax,%ebx
xor    %ebp,%ebp
mov    %r14d,%edi
mov    $0x4,%esi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1030 <send_req@plt>
movzwl %ax,%eax
imul   $0x320,%eax,%eax
add    $0x3e80,%eax
xor    %edx,%edx
idiv   %ebx
mov    %r14d,%edi
mov    $0x8,%esi
mov    %eax,%edx
mov    $0x1,%ecx
call   1030 <send_req@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"ERROR: Overload, this is only 100Mbps Ethernet...\0A\00"
define i32 @u_set_mbps(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* %6
%14 = icmp sgt i32 %13, 100
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %30
18: ; preds = %2
%19 = load i32, i32* %4
%20 = call i32 @send_req(i32 %19, i32 4, i32 -1, i32 0)
%21 = and i32 %20, 65535
%22 = add nsw i32 %21, 20
store i32 %22, i32* %8
%23 = load i32, i32* %8
store i32 %23, i32* %7
%24 = load i32, i32* %4
%25 = load i32, i32* %7
%26 = mul nsw i32 800, %25
%27 = load i32, i32* %6
%28 = sdiv i32 %26, %27
%29 = call i32 @send_req(i32 %24, i32 8, i32 %28, i32 1)
store i32 0, i32* %3
br label %30
30: ; preds = %18, %15
%31 = load i32, i32* %3
ret i32 %31
}

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