#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 /*<<< orphan*/ FNDELAY;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ output(int, char *, ...);
int readHCIResponse(int, unsigned char *, int);
int write(int, unsigned char *, int);
void sendReset(int portFD) {
  unsigned char data[1024];
  int i, ret;
  fcntl(portFD, F_SETFL, FNDELAY);
  data[0] = 0x01;
  data[1] = 0x03;
  data[2] = 0x0c;
  data[3] = 0x00;
  ret = write(portFD, data, 4);
  ret = readHCIResponse(portFD, data, 1024);
  output(1, "Received %i bytes: ", ret);
  if (ret > 0)
    for (i = 0; i < ret; i++)
      output(1, "%02x ", data[i]);
  output(1, "\n");
}


x86 assembly (clang, -O0):
<sendReset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
movb   $0x1,-0x410(%rbp)
movb   $0x3,-0x40f(%rbp)
movb   $0xc,-0x40e(%rbp)
movb   $0x0,-0x40d(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %eax,-0x418(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1060 <readHCIResponse@plt>
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%edx
mov    $0x1,%edi
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1050 <output@plt>
cmpl   $0x0,-0x418(%rbp)
jle    1235 <sendReset+0xf5>
movl   $0x0,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x418(%rbp),%eax
jge    1230 <sendReset+0xf0>
movslq -0x414(%rbp),%rax
movzbl -0x410(%rbp,%rax,1),%edx
ff
mov    $0x1,%edi
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1050 <output@plt>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11e8 <sendReset+0xa8>
jmp    1235 <sendReset+0xf5>
mov    $0x1,%edi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1050 <output@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendReset>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ebx
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
movl   $0xc0301,(%rsp)
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1060 <readHCIResponse@plt>
mov    %eax,%ebx
lea    0xe6a(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <output@plt>
test   %ebx,%ebx
jle    11dc <sendReset+0x9c>
mov    %ebx,%r15d
lea    0xe62(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rsp,%rbx,1),%edx
mov    $0x1,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <output@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11c0 <sendReset+0x80>
lea    0xe37(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <output@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@F_SETFL = global i32 0
@FNDELAY = global i32 0
@.str = [20 x i8] c"Received %i bytes: \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @sendReset(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = load i32, i32* @F_SETFL
%8 = load i32, i32* @FNDELAY
%9 = call i32 @fcntl(i32 %6, i32 %7, i32 %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
store i8 1, i8* %10
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
store i8 3, i8* %11
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 2
store i8 12, i8* %12
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 3
store i8 0, i8* %13
%14 = load i32, i32* %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%16 = call i32 @write(i32 %14, i8* %15, i32 4)
store i32 %16, i32* %5
%17 = load i32, i32* %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = call i32 @readHCIResponse(i32 %17, i8* %18, i32 1024)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = call i32 (i32, i8*, ...) @output(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %5
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %40
24: ; preds = %1
store i32 0, i32* %4
br label %25
25: ; preds = %36, %24
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %25
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = call i32 (i32, i8*, ...) @output(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %25
39: ; preds = %25
br label %40
40: ; preds = %39, %1
%41 = call i32 (i32, i8*, ...) @output(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@F_SETFL = global i32 0
@FNDELAY = global i32 0
@.str = [20 x i8] c"Received %i bytes: \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @sendReset(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @F_SETFL
%5 = load i32, i32* @FNDELAY
%6 = tail call i32 @fcntl(i32 %0, i32 %4, i32 %5)
store i8 1, i8* %3
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1
store i8 3, i8* %7
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 2
store i8 12, i8* %8
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 3
store i8 0, i8* %9
%10 = call i32 @write(i32 %0, i8* %3, i32 4)
%11 = call i32 @readHCIResponse(i32 %0, i8* %3, i32 1024)
%12 = call i32 (i32, i8*, ...) @output(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %24
14: ; preds = %1
%15 = zext i32 %11 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %22, %16 ]
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = call i32 (i32, i8*, ...) @output(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i64 %17, 1
%23 = icmp eq i64 %22, %15
br i1 %23, label %24, label %16
24: ; preds = %16, %1
%25 = call i32 (i32, i8*, ...) @output(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}