#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*/ uint8_t;
typedef int /*<<< orphan*/ uint16_t;
struct mg_connection {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ mg_mqtt_prepend_header(struct mg_connection *, int, int,
                                          int);
int /*<<< orphan*/ mg_send(struct mg_connection *, int /*<<< orphan*/ *, int);
void mg_mqtt_suback(struct mg_connection *nc, uint8_t *qoss, size_t qoss_len,
                    uint16_t message_id) {
  size_t i;
  uint16_t message_id_net = htons(message_id);
  mg_send(nc, &message_id_net, 2);
  for (i = 0; i < qoss_len; i++) {
    mg_send(nc, &qoss[i], 1);
  }
  mg_mqtt_prepend_header(nc, 9, ((1) << 1), 2 + qoss_len);
}


x86 assembly (clang, -O0):
<mg_mqtt_suback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x2,%edx
call   1040 <mg_send@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a8 <mg_mqtt_suback+0x78>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1040 <mg_send@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116c <mg_mqtt_suback+0x3c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %eax,%ecx
mov    $0x9,%esi
mov    $0x2,%edx
call   1050 <mg_mqtt_prepend_header@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mg_mqtt_suback>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %ecx,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %r15,%rdi
mov    $0x2,%edx
call   1040 <mg_send@plt>
test   %r14,%r14
je     118a <mg_mqtt_suback+0x5a>
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <mg_send@plt>
add    $0x4,%r12
add    $0xffffffffffffffff,%rbx
jne    1170 <mg_mqtt_suback+0x40>
add    $0x2,%r14d
mov    %r15,%rdi
mov    $0x9,%esi
mov    $0x2,%edx
mov    %r14d,%ecx
call   1050 <mg_mqtt_prepend_header@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mg_connection = type { i32 }
define void @mg_mqtt_suback(%struct.mg_connection* %0, i32* %1, i64 %2, i32 %3) {
%5 = alloca %struct.mg_connection*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
store %struct.mg_connection* %0, %struct.mg_connection** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = call i32 @htons(i32 %11)
store i32 %12, i32* %10
%13 = load %struct.mg_connection*, %struct.mg_connection** %5
%14 = call i32 @mg_send(%struct.mg_connection* %13, i32* %10, i32 2)
store i64 0, i64* %9
br label %15
15: ; preds = %25, %4
%16 = load i64, i64* %9
%17 = load i64, i64* %7
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load %struct.mg_connection*, %struct.mg_connection** %5
%21 = load i32*, i32** %6
%22 = load i64, i64* %9
%23 = getelementptr inbounds i32, i32* %21, i64 %22
%24 = call i32 @mg_send(%struct.mg_connection* %20, i32* %23, i32 1)
br label %25
25: ; preds = %19
%26 = load i64, i64* %9
%27 = add i64 %26, 1
store i64 %27, i64* %9
br label %15
28: ; preds = %15
%29 = load %struct.mg_connection*, %struct.mg_connection** %5
%30 = load i64, i64* %7
%31 = add i64 2, %30
%32 = trunc i64 %31 to i32
%33 = call i32 @mg_mqtt_prepend_header(%struct.mg_connection* %29, i32 9, i32 2, i32 %32)
ret void
}

LLVM IR (-O2):
%struct.mg_connection = type { i32 }
define void @mg_mqtt_suback(%struct.mg_connection* %0, i32* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i32 @htons(i32 %3)
store i32 %7, i32* %5
%8 = call i32 @mg_send(%struct.mg_connection* %0, i32* %5, i32 2)
%9 = icmp eq i64 %2, 0
br i1 %9, label %16, label %10
10: ; preds = %4, %10
%11 = phi i64 [ %14, %10 ], [ 0, %4 ]
%12 = getelementptr inbounds i32, i32* %1, i64 %11
%13 = call i32 @mg_send(%struct.mg_connection* %0, i32* %12, i32 1)
%14 = add nuw i64 %11, 1
%15 = icmp eq i64 %14, %2
br i1 %15, label %16, label %10
16: ; preds = %10, %4
%17 = trunc i64 %2 to i32
%18 = add i32 %17, 2
%19 = call i32 @mg_mqtt_prepend_header(%struct.mg_connection* %0, i32 9, i32 2, i32 %18)
ret void
}