#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 read(int, unsigned char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int set_freq(int fd, int channel, int output, int freq, short pll_freq,
             int r_div) {
  unsigned char message[10];
  int n;
  message[0] = 4;
  message[1] = freq & 0xFF;
  message[2] = (freq >> 8) & 0xFF;
  message[3] = (freq >> 16) & 0xFF;
  message[4] = freq >> 24;
  message[5] = pll_freq & 0xFF;
  message[6] = (pll_freq >> 8) & 0xFF;
  message[7] = channel;
  message[8] = output;
  message[9] = r_div;
  write(fd, message, 10);
  usleep(100000);
  n = read(fd, message, 1);
  return n != 1 || message[0] != 'k';
}


x86 assembly (clang, -O0):
<set_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8w,%ax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    %r9d,-0x18(%rbp)
movb   $0x4,-0x22(%rbp)
mov    -0x10(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x20(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x1f(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x18,%eax
mov    %al,-0x1e(%rbp)
movswl -0x12(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x1d(%rbp)
movswl -0x12(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0x1b(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0x1a(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0x19(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    $0x186a0,%edi
call   1050 <usleep@plt>
mov    -0x4(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x28(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x28(%rbp)
mov    %al,-0x29(%rbp)
jne    11fc <set_freq+0xcc>
movzbl -0x22(%rbp),%eax
cmp    $0x6b,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_freq>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%eax
mov    %edi,%ebx
movb   $0x4,0xe(%rsp)
mov    %cl,0xf(%rsp)
mov    %ch,0x10(%rsp)
mov    %ecx,%edi
shr    $0x10,%edi
mov    %dil,0x11(%rsp)
shr    $0x18,%ecx
mov    %cl,0x12(%rsp)
mov    %al,0x13(%rsp)
mov    %ah,0x14(%rsp)
mov    %sil,0x15(%rsp)
mov    %dl,0x16(%rsp)
mov    %r9b,0x17(%rsp)
lea    0xe(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    $0x186a0,%edi
call   1050 <usleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
setne  %al
cmpb   $0x6b,0xe(%rsp)
setne  %cl
or     %al,%cl
movzbl %cl,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @set_freq(i32 %0, i32 %1, i32 %2, i32 %3, i16 signext %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i16
%12 = alloca i32
%13 = alloca [10 x i8]
%14 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i16 %4, i16* %11
store i32 %5, i32* %12
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 0
store i8 4, i8* %15
%16 = load i32, i32* %10
%17 = and i32 %16, 255
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 1
store i8 %18, i8* %19
%20 = load i32, i32* %10
%21 = ashr i32 %20, 8
%22 = and i32 %21, 255
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 2
store i8 %23, i8* %24
%25 = load i32, i32* %10
%26 = ashr i32 %25, 16
%27 = and i32 %26, 255
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 3
store i8 %28, i8* %29
%30 = load i32, i32* %10
%31 = ashr i32 %30, 24
%32 = trunc i32 %31 to i8
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 4
store i8 %32, i8* %33
%34 = load i16, i16* %11
%35 = sext i16 %34 to i32
%36 = and i32 %35, 255
%37 = trunc i32 %36 to i8
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 5
store i8 %37, i8* %38
%39 = load i16, i16* %11
%40 = sext i16 %39 to i32
%41 = ashr i32 %40, 8
%42 = and i32 %41, 255
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 6
store i8 %43, i8* %44
%45 = load i32, i32* %8
%46 = trunc i32 %45 to i8
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 7
store i8 %46, i8* %47
%48 = load i32, i32* %9
%49 = trunc i32 %48 to i8
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 8
store i8 %49, i8* %50
%51 = load i32, i32* %12
%52 = trunc i32 %51 to i8
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 9
store i8 %52, i8* %53
%54 = load i32, i32* %7
%55 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 0
%56 = call i32 @write(i32 %54, i8* %55, i32 10)
%57 = call i32 @usleep(i32 100000)
%58 = load i32, i32* %7
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 0
%60 = call i32 @read(i32 %58, i8* %59, i32 1)
store i32 %60, i32* %14
%61 = load i32, i32* %14
%62 = icmp ne i32 %61, 1
br i1 %62, label %68, label %63
63: ; preds = %6
%64 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 0
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = icmp ne i32 %66, 107
br label %68
68: ; preds = %63, %6
%69 = phi i1 [ true, %6 ], [ %67, %63 ]
%70 = zext i1 %69 to i32
ret i32 %70
}

LLVM IR (-O2):
define i32 @set_freq(i32 %0, i32 %1, i32 %2, i32 %3, i16 signext %4, i32 %5) {
%7 = alloca [10 x i8]
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
store i8 4, i8* %8
%9 = trunc i32 %3 to i8
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 1
store i8 %9, i8* %10
%11 = lshr i32 %3, 8
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 2
store i8 %12, i8* %13
%14 = lshr i32 %3, 16
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 3
store i8 %15, i8* %16
%17 = lshr i32 %3, 24
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 4
store i8 %18, i8* %19
%20 = trunc i16 %4 to i8
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 5
store i8 %20, i8* %21
%22 = lshr i16 %4, 8
%23 = trunc i16 %22 to i8
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 6
store i8 %23, i8* %24
%25 = trunc i32 %1 to i8
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 7
store i8 %25, i8* %26
%27 = trunc i32 %2 to i8
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 8
store i8 %27, i8* %28
%29 = trunc i32 %5 to i8
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 9
store i8 %29, i8* %30
%31 = call i32 @write(i32 %0, i8* %8, i32 10)
%32 = tail call i32 @usleep(i32 100000)
%33 = call i32 @read(i32 %0, i8* %8, i32 1)
%34 = icmp ne i32 %33, 1
%35 = load i8, i8* %8
%36 = icmp ne i8 %35, 107
%37 = select i1 %34, i1 true, i1 %36
%38 = zext i1 %37 to i32
ret i32 %38
}