#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 ushort;

/* Variables and functions */
unsigned char msg_send(int, unsigned char *, int);
unsigned char ANT_SetChannelId(unsigned char chan, ushort dev,
                               unsigned char devtype, unsigned char manid) {
  unsigned char buf[5];
  buf[0] = chan;
  buf[1] = dev % 256;
  buf[2] = dev / 256;
  buf[3] = devtype;
  buf[4] = manid;
  return msg_send(0x51, buf, 5);
}


x86 assembly (clang, -O0):
<ANT_SetChannelId>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    -0x1(%rbp),%al
mov    %al,-0xf(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0xe(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %al,-0xd(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0xc(%rbp)
mov    -0xa(%rbp),%al
mov    %al,-0xb(%rbp)
lea    -0xf(%rbp),%rsi
mov    $0x51,%edi
mov    $0x5,%edx
call   1030 <msg_send@plt>
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ANT_SetChannelId>:
push   %rax
mov    %dil,0x3(%rsp)
lea    0xff(%rsi),%eax
test   %esi,%esi
cmovns %esi,%eax
mov    %sil,0x4(%rsp)
mov    %ah,0x5(%rsp)
mov    %dl,0x6(%rsp)
mov    %cl,0x7(%rsp)
lea    0x3(%rsp),%rsi
mov    $0x51,%edi
mov    $0x5,%edx
call   1030 <msg_send@plt>
pop    %rcx
ret

LLVM IR (-O0):
define zeroext i8 @ANT_SetChannelId(i8 zeroext %0, i32 %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca [5 x i8]
store i8 %0, i8* %5
store i32 %1, i32* %6
store i8 %2, i8* %7
store i8 %3, i8* %8
%10 = load i8, i8* %5
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
store i8 %10, i8* %11
%12 = load i32, i32* %6
%13 = srem i32 %12, 256
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 1
store i8 %14, i8* %15
%16 = load i32, i32* %6
%17 = sdiv i32 %16, 256
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 2
store i8 %18, i8* %19
%20 = load i8, i8* %7
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 3
store i8 %20, i8* %21
%22 = load i8, i8* %8
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 4
store i8 %22, i8* %23
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%25 = call zeroext i8 @msg_send(i32 81, i8* %24, i32 5)
ret i8 %25
}

LLVM IR (-O2):
define zeroext i8 @ANT_SetChannelId(i8 zeroext %0, i32 %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca [5 x i8]
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
store i8 %0, i8* %6
%7 = trunc i32 %1 to i8
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 1
store i8 %7, i8* %8
%9 = sdiv i32 %1, 256
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 2
store i8 %10, i8* %11
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 3
store i8 %2, i8* %12
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 4
store i8 %3, i8* %13
%14 = call zeroext i8 @msg_send(i32 81, i8* %6, i32 5)
ret i8 %14
}