#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 */
struct mbuff {
  int dummy;
};
struct mb_queue {
  int dummy;
};

/* Variables and functions */
struct mbuff *alloc_mbuff();
int /*<<< orphan*/ init_mbuff_queue(struct mb_queue *);
int /*<<< orphan*/ mbuff_enqueue(struct mb_queue *, struct mbuff *);
size_t alloc_mbuff_queue(struct mb_queue *queue, size_t len) {
  struct mbuff *mb;
  size_t i;
  init_mbuff_queue(queue);
  if (!len)
    return 0;
  for (i = 0; i < len; i++) {
    mb = alloc_mbuff();
    if (mb)
      mbuff_enqueue(queue, mb);
    else
      break;
  }
  return i;
}


x86 assembly (clang, -O0):
<alloc_mbuff_queue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <init_mbuff_queue@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1161 <alloc_mbuff_queue+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11c2 <alloc_mbuff_queue+0x92>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ba <alloc_mbuff_queue+0x8a>
mov    $0x0,%al
call   1050 <alloc_mbuff@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119f <alloc_mbuff_queue+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <mbuff_enqueue@plt>
jmp    11a4 <alloc_mbuff_queue+0x74>
jmp    11ba <alloc_mbuff_queue+0x8a>
jmp    11a9 <alloc_mbuff_queue+0x79>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1169 <alloc_mbuff_queue+0x39>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_mbuff_queue>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <init_mbuff_queue@plt>
xor    %ebx,%ebx
test   %r14,%r14
je     1173 <alloc_mbuff_queue+0x43>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <alloc_mbuff@plt>
test   %rax,%rax
je     1173 <alloc_mbuff_queue+0x43>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <mbuff_enqueue@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <alloc_mbuff_queue+0x20>
mov    %r14,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mb_queue = type { i32 }
%struct.mbuff = type { i32 }
define i64 @alloc_mbuff_queue(%struct.mb_queue* %0, i64 %1) {
%3 = alloca i64
%4 = alloca %struct.mb_queue*
%5 = alloca i64
%6 = alloca %struct.mbuff*
%7 = alloca i64
store %struct.mb_queue* %0, %struct.mb_queue** %4
store i64 %1, i64* %5
%8 = load %struct.mb_queue*, %struct.mb_queue** %4
%9 = call i32 @init_mbuff_queue(%struct.mb_queue* %8)
%10 = load i64, i64* %5
%11 = icmp ne i64 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i64 0, i64* %3
br label %33
13: ; preds = %2
store i64 0, i64* %7
br label %14
14: ; preds = %28, %13
%15 = load i64, i64* %7
%16 = load i64, i64* %5
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = call %struct.mbuff* (...) @alloc_mbuff()
store %struct.mbuff* %19, %struct.mbuff** %6
%20 = load %struct.mbuff*, %struct.mbuff** %6
%21 = icmp ne %struct.mbuff* %20, null
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load %struct.mb_queue*, %struct.mb_queue** %4
%24 = load %struct.mbuff*, %struct.mbuff** %6
%25 = call i32 @mbuff_enqueue(%struct.mb_queue* %23, %struct.mbuff* %24)
br label %27
26: ; preds = %18
br label %31
27: ; preds = %22
br label %28
28: ; preds = %27
%29 = load i64, i64* %7
%30 = add i64 %29, 1
store i64 %30, i64* %7
br label %14
31: ; preds = %26, %14
%32 = load i64, i64* %7
store i64 %32, i64* %3
br label %33
33: ; preds = %31, %12
%34 = load i64, i64* %3
ret i64 %34
}

LLVM IR (-O2):
%struct.mb_queue = type { i32 }
%struct.mbuff = type { i32 }
define i64 @alloc_mbuff_queue(%struct.mb_queue* %0, i64 %1) {
%3 = tail call i32 @init_mbuff_queue(%struct.mb_queue* %0)
%4 = icmp eq i64 %1, 0
br i1 %4, label %13, label %5
5: ; preds = %2, %9
%6 = phi i64 [ %11, %9 ], [ 0, %2 ]
%7 = tail call %struct.mbuff* (...) @alloc_mbuff()
%8 = icmp eq %struct.mbuff* %7, null
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = tail call i32 @mbuff_enqueue(%struct.mb_queue* %0, %struct.mbuff* %7)
%11 = add nuw i64 %6, 1
%12 = icmp eq i64 %11, %1
br i1 %12, label %13, label %5
13: ; preds = %5, %9, %2
%14 = phi i64 [ 0, %2 ], [ %6, %5 ], [ %1, %9 ]
ret i64 %14
}