#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 /*<<< orphan*/ setrumble;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ recv(int, unsigned char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, unsigned char *, int, int /*<<< orphan*/);
void do_rumble(int csk, int led_n, int weak, int strong, int timeout) {
  unsigned char buf[128];
  unsigned char setrumble[] = {0x52, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                               0x00, 0x00, 0x00, 0x1E, 0xff, 0x27, 0x10, 0x00,
                               0x32, 0xff, 0x27, 0x10, 0x00, 0x32, 0xff, 0x27,
                               0x10, 0x00, 0x32, 0xff, 0x27, 0x10, 0x00, 0x32,
                               0x00, 0x00, 0x00, 0x00, 0x00};
  const unsigned char ledpattern[11] = {0x00, 0x02, 0x04, 0x08, 0x10, 0x12,
                                        0x14, 0x18, 0x1A, 0x1C, 0x1E};
  weak *= 10;
  strong *= 10;
  timeout *= 10;
  if (weak > 0xff)
    weak = 0xff;
  else if (weak < 0)
    weak = 0;
  if (strong > 0xff)
    strong = 0xff;
  else if (strong < 0)
    strong = 0;
  if (timeout > 0xff)
    timeout = 0xff;
  else if (timeout < 4)
    timeout = 4;
  setrumble[3] = setrumble[5] = timeout;
  setrumble[4] = weak;
  setrumble[6] = strong;
  setrumble[11] = ledpattern[led_n];
  send(csk, setrumble, sizeof(setrumble), 0);
  recv(csk, buf, sizeof(buf), 0);
}


x86 assembly (clang, -O0):
<do_rumble>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
lea    -0xd0(%rbp),%rdi
lea    0xea7(%rip),%rsi
mov    $0x25,%edx
call   1050 <memcpy@plt>
mov    0xebb(%rip),%rax
mov    %rax,-0xdb(%rbp)
mov    0xeb5(%rip),%ax
mov    %ax,-0xd3(%rbp)
mov    0xeaa(%rip),%al
mov    %al,-0xd1(%rbp)
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
imul   $0xa,-0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xff,-0xc(%rbp)
jle    11b9 <do_rumble+0x89>
movl   $0xff,-0xc(%rbp)
jmp    11cf <do_rumble+0x9f>
cmpl   $0x0,-0xc(%rbp)
jge    11ca <do_rumble+0x9a>
movl   $0x0,-0xc(%rbp)
jmp    11cf <do_rumble+0x9f>
cmpl   $0xff,-0x10(%rbp)
jle    11e8 <do_rumble+0xb8>
movl   $0xff,-0x10(%rbp)
jmp    11fe <do_rumble+0xce>
cmpl   $0x0,-0x10(%rbp)
jge    11f9 <do_rumble+0xc9>
movl   $0x0,-0x10(%rbp)
jmp    11fe <do_rumble+0xce>
cmpl   $0xff,-0x14(%rbp)
jle    1217 <do_rumble+0xe7>
movl   $0xff,-0x14(%rbp)
jmp    122d <do_rumble+0xfd>
cmpl   $0x4,-0x14(%rbp)
jge    1228 <do_rumble+0xf8>
movl   $0x4,-0x14(%rbp)
jmp    122d <do_rumble+0xfd>
mov    -0x14(%rbp),%eax
mov    %al,-0xcb(%rbp)
mov    %al,-0xcd(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0xcc(%rbp)
mov    -0x10(%rbp),%eax
mov    %al,-0xca(%rbp)
movslq -0x8(%rbp),%rax
mov    -0xdb(%rbp,%rax,1),%al
mov    %al,-0xc5(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    $0x25,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_rumble>:
push   %rbp
push   %rbx
sub    $0xb8,%rsp
mov    %edi,%ebp
movaps 0xece(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xed3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
add    %edx,%edx
lea    (%rdx,%rdx,4),%eax
add    %ecx,%ecx
add    %r8d,%r8d
xor    %edx,%edx
test   %eax,%eax
cmovs  %edx,%eax
cmp    $0xff,%eax
mov    $0xff,%edi
cmovae %edi,%eax
lea    (%rcx,%rcx,4),%ecx
test   %ecx,%ecx
cmovs  %edx,%ecx
lea    (%r8,%r8,4),%edx
cmp    $0xff,%ecx
cmovae %edi,%ecx
cmp    $0x5,%edx
mov    $0x4,%ebx
cmovge %edx,%ebx
movq   $0x320010,0x1d(%rsp)
cmp    $0xff,%ebx
cmovae %edi,%ebx
mov    %bl,0x5(%rsp)
mov    %bl,0x3(%rsp)
mov    %al,0x4(%rsp)
mov    %cl,0x6(%rsp)
movslq %esi,%rax
lea    0xe79(%rip),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,0xb(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x25,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    0x30(%rsp),%rsi
mov    %ebp,%edi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
add    $0xb8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.do_rumble.setrumble = [37 x i8] c"R\01\00\00\00\00\00\00\00\00\00\1E\FF'\10\002\FF'\10\002\FF'\10\002\FF'\10\002\00\00\00\00\00"
@__const.do_rumble.ledpattern = [11 x i8] c"\00\02\04\08\10\12\14\18\1A\1C\1E"
define void @do_rumble(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [128 x i8]
%12 = alloca [37 x i8]
%13 = alloca [11 x i8]
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%14 = bitcast [37 x i8]* %12 to i8*
%15 = bitcast [11 x i8]* %13 to i8*
%16 = load i32, i32* %8
%17 = mul nsw i32 %16, 10
store i32 %17, i32* %8
%18 = load i32, i32* %9
%19 = mul nsw i32 %18, 10
store i32 %19, i32* %9
%20 = load i32, i32* %10
%21 = mul nsw i32 %20, 10
store i32 %21, i32* %10
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 255
br i1 %23, label %24, label %25
24: ; preds = %5
store i32 255, i32* %8
br label %30
25: ; preds = %5
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 0, i32* %8
br label %29
29: ; preds = %28, %25
br label %30
30: ; preds = %29, %24
%31 = load i32, i32* %9
%32 = icmp sgt i32 %31, 255
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 255, i32* %9
br label %39
34: ; preds = %30
%35 = load i32, i32* %9
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 0, i32* %9
br label %38
38: ; preds = %37, %34
br label %39
39: ; preds = %38, %33
%40 = load i32, i32* %10
%41 = icmp sgt i32 %40, 255
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 255, i32* %10
br label %48
43: ; preds = %39
%44 = load i32, i32* %10
%45 = icmp slt i32 %44, 4
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 4, i32* %10
br label %47
47: ; preds = %46, %43
br label %48
48: ; preds = %47, %42
%49 = load i32, i32* %10
%50 = trunc i32 %49 to i8
%51 = getelementptr inbounds [37 x i8], [37 x i8]* %12, i64 0, i64 5
store i8 %50, i8* %51
%52 = getelementptr inbounds [37 x i8], [37 x i8]* %12, i64 0, i64 3
store i8 %50, i8* %52
%53 = load i32, i32* %8
%54 = trunc i32 %53 to i8
%55 = getelementptr inbounds [37 x i8], [37 x i8]* %12, i64 0, i64 4
store i8 %54, i8* %55
%56 = load i32, i32* %9
%57 = trunc i32 %56 to i8
%58 = getelementptr inbounds [37 x i8], [37 x i8]* %12, i64 0, i64 6
store i8 %57, i8* %58
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [11 x i8], [11 x i8]* %13, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = getelementptr inbounds [37 x i8], [37 x i8]* %12, i64 0, i64 11
store i8 %62, i8* %63
%64 = load i32, i32* %6
%65 = getelementptr inbounds [37 x i8], [37 x i8]* %12, i64 0, i64 0
%66 = call i32 @send(i32 %64, i8* %65, i32 37, i32 0)
%67 = load i32, i32* %6
%68 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%69 = call i32 @recv(i32 %67, i8* %68, i32 128, i32 0)
ret void
}

LLVM IR (-O2):
@__const.do_rumble.setrumble = [37 x i8] c"R\01\00\00\00\00\00\00\00\00\00\1E\FF'\10\002\FF'\10\002\FF'\10\002\FF'\10\002\00\00\00\00\00"
@__const.do_rumble.ledpattern = [11 x i8] c"\00\02\04\08\10\12\14\18\1A\1C\1E"
define void @do_rumble(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [128 x i8]
%7 = alloca [37 x i8]
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [37 x i8], [37 x i8]* %7, i64 0, i64 0
%10 = mul nsw i32 %2, 10
%11 = mul nsw i32 %3, 10
%12 = mul nsw i32 %4, 10
%13 = icmp sgt i32 %10, 0
%14 = select i1 %13, i32 %10, i32 0
%15 = icmp ult i32 %14, 255
%16 = select i1 %15, i32 %14, i32 255
%17 = trunc i32 %16 to i8
%18 = icmp sgt i32 %11, 0
%19 = select i1 %18, i32 %11, i32 0
%20 = icmp ult i32 %19, 255
%21 = select i1 %20, i32 %19, i32 255
%22 = trunc i32 %21 to i8
%23 = icmp sgt i32 %12, 4
%24 = select i1 %23, i32 %12, i32 4
%25 = icmp ult i32 %24, 255
%26 = select i1 %25, i32 %24, i32 255
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds [37 x i8], [37 x i8]* %7, i64 0, i64 5
store i8 %27, i8* %28
%29 = getelementptr inbounds [37 x i8], [37 x i8]* %7, i64 0, i64 3
store i8 %27, i8* %29
%30 = getelementptr inbounds [37 x i8], [37 x i8]* %7, i64 0, i64 4
store i8 %17, i8* %30
%31 = getelementptr inbounds [37 x i8], [37 x i8]* %7, i64 0, i64 6
store i8 %22, i8* %31
%32 = sext i32 %1 to i64
%33 = getelementptr inbounds [11 x i8], [11 x i8]* @__const.do_rumble.ledpattern, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = getelementptr inbounds [37 x i8], [37 x i8]* %7, i64 0, i64 11
store i8 %34, i8* %35
%36 = call i32 @send(i32 %0, i8* %9, i32 37, i32 0)
%37 = call i32 @recv(i32 %0, i8* %8, i32 128, i32 0)
ret void
}