#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 uint32_t;
typedef int uint16_t;
typedef int /*<<< orphan*/ mem;

/* Variables and functions */
void *mem_acquire(void **);
int mem_free_count_get(void *);
int /*<<< orphan*/ mem_init(int /*<<< orphan*/ **, int, int, void **);
int /*<<< orphan*/ mem_release(void *, void **);
int /*<<< orphan*/ memcpy(void **, void *, int);
uint32_t mem_ut(void) {
  uint8_t __attribute__((aligned(4)))
  pool[10][(((uint32_t)(10) + 3) & (~((uint32_t)3)))];
  void *mem_free;
  void *mem_used;
  uint16_t mem_free_count;
  void *mem;
  mem_init(pool, (((uint32_t)(10) + 3) & (~((uint32_t)3))), 10, &mem_free);
  mem_free_count = mem_free_count_get(mem_free);
  if (mem_free_count != 10) {
    return 1;
  }
  mem_used = 0;
  while (mem_free_count--) {
    uint16_t mem_free_count_current;
    mem = mem_acquire(&mem_free);
    mem_free_count_current = mem_free_count_get(mem_free);
    if (mem_free_count != mem_free_count_current) {
      return 2;
    }
    memcpy(mem, &mem_used, sizeof(mem));
    mem_used = mem;
  }
  mem = mem_acquire(&mem_free);
  if (mem) {
    return 3;
  }
  while (++mem_free_count < 10) {
    uint16_t mem_free_count_current;
    mem = mem_used;
    memcpy(&mem_used, mem, sizeof(void *));
    mem_release(mem, &mem_free);
    mem_free_count_current = mem_free_count_get(mem_free);
    if ((mem_free_count + 1) != mem_free_count_current) {
      return 4;
    }
  }
  if (mem != mem_free) {
    return 5;
  }
  if (mem_free_count_get(mem_free) != 10) {
    return 6;
  }
  return 0;
}


x86 assembly (clang, -O0):
<mem_ut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
lea    -0x1e4(%rbp),%rdi
mov    $0xc,%esi
mov    $0xa,%edx
lea    -0x1f0(%rbp),%rcx
call   1030 <mem_init@plt>
mov    -0x1f0(%rbp),%rdi
call   1040 <mem_free_count_get@plt>
mov    %eax,-0x1fc(%rbp)
cmpl   $0xa,-0x1fc(%rbp)
je     11a3 <mem_ut+0x53>
movl   $0x1,-0x4(%rbp)
jmp    1339 <mem_ut+0x1e9>
movq   $0x0,-0x1f8(%rbp)
mov    -0x1fc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1fc(%rbp)
cmp    $0x0,%eax
je     1236 <mem_ut+0xe6>
lea    -0x1f0(%rbp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,-0x208(%rbp)
mov    -0x1f0(%rbp),%rdi
call   1040 <mem_free_count_get@plt>
mov    %eax,-0x20c(%rbp)
mov    -0x1fc(%rbp),%eax
cmp    -0x20c(%rbp),%eax
je     120b <mem_ut+0xbb>
movl   $0x2,-0x4(%rbp)
jmp    1339 <mem_ut+0x1e9>
mov    -0x208(%rbp),%rdi
lea    -0x1f8(%rbp),%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    -0x208(%rbp),%rax
mov    %rax,-0x1f8(%rbp)
jmp    11ae <mem_ut+0x5e>
lea    -0x1f0(%rbp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,-0x208(%rbp)
cmpq   $0x0,-0x208(%rbp)
je     1263 <mem_ut+0x113>
movl   $0x3,-0x4(%rbp)
jmp    1339 <mem_ut+0x1e9>
jmp    1268 <mem_ut+0x118>
mov    -0x1fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1fc(%rbp)
cmp    $0xa,%eax
jge    12f1 <mem_ut+0x1a1>
mov    -0x1f8(%rbp),%rax
mov    %rax,-0x208(%rbp)
mov    -0x208(%rbp),%rsi
lea    -0x1f8(%rbp),%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    -0x208(%rbp),%rdi
lea    -0x1f0(%rbp),%rsi
call   1070 <mem_release@plt>
mov    -0x1f0(%rbp),%rdi
call   1040 <mem_free_count_get@plt>
mov    %eax,-0x210(%rbp)
mov    -0x1fc(%rbp),%eax
add    $0x1,%eax
cmp    -0x210(%rbp),%eax
je     12ec <mem_ut+0x19c>
movl   $0x4,-0x4(%rbp)
jmp    1339 <mem_ut+0x1e9>
jmp    1268 <mem_ut+0x118>
mov    -0x208(%rbp),%rax
cmp    -0x1f0(%rbp),%rax
je     1311 <mem_ut+0x1c1>
movl   $0x5,-0x4(%rbp)
jmp    1339 <mem_ut+0x1e9>
mov    -0x1f0(%rbp),%rdi
call   1040 <mem_free_count_get@plt>
cmp    $0xa,%eax
je     1332 <mem_ut+0x1e2>
movl   $0x6,-0x4(%rbp)
jmp    1339 <mem_ut+0x1e9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_ut>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1f8,%rsp
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    $0xc,%esi
mov    $0xa,%edx
call   1030 <mem_init@plt>
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
mov    $0x1,%ebp
cmp    $0xa,%eax
jne    1442 <mem_ut+0x2f2>
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
mov    $0x2,%ebp
cmp    $0x9,%eax
jne    1442 <mem_ut+0x2f2>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbx,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
cmp    $0x8,%eax
jne    1442 <mem_ut+0x2f2>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbx,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
cmp    $0x7,%eax
jne    1442 <mem_ut+0x2f2>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbx,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
cmp    $0x6,%eax
jne    1442 <mem_ut+0x2f2>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbx,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
cmp    $0x5,%eax
jne    1442 <mem_ut+0x2f2>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbx,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
cmp    $0x4,%eax
jne    1442 <mem_ut+0x2f2>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbx,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
cmp    $0x3,%eax
jne    1442 <mem_ut+0x2f2>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbx,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
cmp    $0x2,%eax
jne    1442 <mem_ut+0x2f2>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbx,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
cmp    $0x1,%eax
jne    1442 <mem_ut+0x2f2>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbx,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    %rax,%r14
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
test   %eax,%eax
jne    1442 <mem_ut+0x2f2>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %r14,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mem_acquire@plt>
mov    $0x3,%ebp
test   %rax,%rax
jne    1442 <mem_ut+0x2f2>
mov    $0x1,%ebp
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%rbx
mov    0x10(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <mem_release@plt>
mov    0x8(%rsp),%rdi
call   1040 <mem_free_count_get@plt>
cmp    %eax,%ebp
jne    143d <mem_ut+0x2ed>
add    $0x1,%ebp
cmp    $0xb,%ebp
jne    13e4 <mem_ut+0x294>
mov    $0x5,%ebp
cmp    0x8(%rsp),%r14
jne    1442 <mem_ut+0x2f2>
mov    %r14,%rdi
call   1040 <mem_free_count_get@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
mov    $0x6,%ebp
cmove  %ecx,%ebp
jmp    1442 <mem_ut+0x2f2>
mov    $0x4,%ebp
mov    %ebp,%eax
add    $0x1f8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mem_ut() {
%1 = alloca i32
%2 = alloca [10 x [12 x i32]]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [10 x [12 x i32]], [10 x [12 x i32]]* %2, i64 0, i64 0
%10 = bitcast [12 x i32]* %9 to i32**
%11 = call i32 @mem_init(i32** %10, i32 12, i32 10, i8** %3)
%12 = load i8*, i8** %3
%13 = call i32 @mem_free_count_get(i8* %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %17
16: ; preds = %0
store i32 1, i32* %1
br label %71
17: ; preds = %0
store i8* null, i8** %4
br label %18
18: ; preds = %30, %17
%19 = load i32, i32* %5
%20 = add nsw i32 %19, -1
store i32 %20, i32* %5
%21 = icmp ne i32 %19, 0
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = call i8* @mem_acquire(i8** %3)
store i8* %23, i8** %6
%24 = load i8*, i8** %3
%25 = call i32 @mem_free_count_get(i8* %24)
store i32 %25, i32* %7
%26 = load i32, i32* %5
%27 = load i32, i32* %7
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 2, i32* %1
br label %71
30: ; preds = %22
%31 = load i8*, i8** %6
%32 = bitcast i8* %31 to i8**
%33 = bitcast i8** %4 to i8*
%34 = call i32 @memcpy(i8** %32, i8* %33, i32 8)
%35 = load i8*, i8** %6
store i8* %35, i8** %4
br label %18
36: ; preds = %18
%37 = call i8* @mem_acquire(i8** %3)
store i8* %37, i8** %6
%38 = load i8*, i8** %6
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %41
40: ; preds = %36
store i32 3, i32* %1
br label %71
41: ; preds = %36
br label %42
42: ; preds = %59, %41
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
%45 = icmp slt i32 %44, 10
br i1 %45, label %46, label %60
46: ; preds = %42
%47 = load i8*, i8** %4
store i8* %47, i8** %6
%48 = load i8*, i8** %6
%49 = call i32 @memcpy(i8** %4, i8* %48, i32 8)
%50 = load i8*, i8** %6
%51 = call i32 @mem_release(i8* %50, i8** %3)
%52 = load i8*, i8** %3
%53 = call i32 @mem_free_count_get(i8* %52)
store i32 %53, i32* %8
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
%56 = load i32, i32* %8
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %59
58: ; preds = %46
store i32 4, i32* %1
br label %71
59: ; preds = %46
br label %42
60: ; preds = %42
%61 = load i8*, i8** %6
%62 = load i8*, i8** %3
%63 = icmp ne i8* %61, %62
br i1 %63, label %64, label %65
64: ; preds = %60
store i32 5, i32* %1
br label %71
65: ; preds = %60
%66 = load i8*, i8** %3
%67 = call i32 @mem_free_count_get(i8* %66)
%68 = icmp ne i32 %67, 10
br i1 %68, label %69, label %70
69: ; preds = %65
store i32 6, i32* %1
br label %71
70: ; preds = %65
store i32 0, i32* %1
br label %71
71: ; preds = %70, %69, %64, %58, %40, %29, %16
%72 = load i32, i32* %1
ret i32 %72
}

LLVM IR (-O2):
define i32 @mem_ut() {
%1 = alloca [10 x [12 x i32]]
%2 = alloca i8*
%3 = alloca i8*
%4 = bitcast [10 x [12 x i32]]* %1 to i8*
%5 = bitcast i8** %2 to i8*
%6 = bitcast i8** %3 to i8*
%7 = bitcast [10 x [12 x i32]]* %1 to i32**
%8 = call i32 @mem_init(i32** %7, i32 12, i32 10, i8** %2)
%9 = load i8*, i8** %2
%10 = call i32 @mem_free_count_get(i8* %9)
%11 = icmp eq i32 %10, 10
br i1 %11, label %12, label %104
12: ; preds = %0
store i8* null, i8** %3
%13 = call i8* @mem_acquire(i8** %2)
%14 = load i8*, i8** %2
%15 = call i32 @mem_free_count_get(i8* %14)
%16 = icmp eq i32 %15, 9
br i1 %16, label %17, label %104
17: ; preds = %12
%18 = bitcast i8* %13 to i8**
%19 = call i32 @memcpy(i8** %18, i8* %6, i32 8)
store i8* %13, i8** %3
%20 = call i8* @mem_acquire(i8** %2)
%21 = load i8*, i8** %2
%22 = call i32 @mem_free_count_get(i8* %21)
%23 = icmp eq i32 %22, 8
br i1 %23, label %24, label %104
24: ; preds = %17
%25 = bitcast i8* %20 to i8**
%26 = call i32 @memcpy(i8** %25, i8* %6, i32 8)
store i8* %20, i8** %3
%27 = call i8* @mem_acquire(i8** %2)
%28 = load i8*, i8** %2
%29 = call i32 @mem_free_count_get(i8* %28)
%30 = icmp eq i32 %29, 7
br i1 %30, label %31, label %104
31: ; preds = %24
%32 = bitcast i8* %27 to i8**
%33 = call i32 @memcpy(i8** %32, i8* %6, i32 8)
store i8* %27, i8** %3
%34 = call i8* @mem_acquire(i8** %2)
%35 = load i8*, i8** %2
%36 = call i32 @mem_free_count_get(i8* %35)
%37 = icmp eq i32 %36, 6
br i1 %37, label %38, label %104
38: ; preds = %31
%39 = bitcast i8* %34 to i8**
%40 = call i32 @memcpy(i8** %39, i8* %6, i32 8)
store i8* %34, i8** %3
%41 = call i8* @mem_acquire(i8** %2)
%42 = load i8*, i8** %2
%43 = call i32 @mem_free_count_get(i8* %42)
%44 = icmp eq i32 %43, 5
br i1 %44, label %45, label %104
45: ; preds = %38
%46 = bitcast i8* %41 to i8**
%47 = call i32 @memcpy(i8** %46, i8* %6, i32 8)
store i8* %41, i8** %3
%48 = call i8* @mem_acquire(i8** %2)
%49 = load i8*, i8** %2
%50 = call i32 @mem_free_count_get(i8* %49)
%51 = icmp eq i32 %50, 4
br i1 %51, label %52, label %104
52: ; preds = %45
%53 = bitcast i8* %48 to i8**
%54 = call i32 @memcpy(i8** %53, i8* %6, i32 8)
store i8* %48, i8** %3
%55 = call i8* @mem_acquire(i8** %2)
%56 = load i8*, i8** %2
%57 = call i32 @mem_free_count_get(i8* %56)
%58 = icmp eq i32 %57, 3
br i1 %58, label %59, label %104
59: ; preds = %52
%60 = bitcast i8* %55 to i8**
%61 = call i32 @memcpy(i8** %60, i8* %6, i32 8)
store i8* %55, i8** %3
%62 = call i8* @mem_acquire(i8** %2)
%63 = load i8*, i8** %2
%64 = call i32 @mem_free_count_get(i8* %63)
%65 = icmp eq i32 %64, 2
br i1 %65, label %66, label %104
66: ; preds = %59
%67 = bitcast i8* %62 to i8**
%68 = call i32 @memcpy(i8** %67, i8* %6, i32 8)
store i8* %62, i8** %3
%69 = call i8* @mem_acquire(i8** %2)
%70 = load i8*, i8** %2
%71 = call i32 @mem_free_count_get(i8* %70)
%72 = icmp eq i32 %71, 1
br i1 %72, label %73, label %104
73: ; preds = %66
%74 = bitcast i8* %69 to i8**
%75 = call i32 @memcpy(i8** %74, i8* %6, i32 8)
store i8* %69, i8** %3
%76 = call i8* @mem_acquire(i8** %2)
%77 = load i8*, i8** %2
%78 = call i32 @mem_free_count_get(i8* %77)
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %104
80: ; preds = %73
%81 = bitcast i8* %76 to i8**
%82 = call i32 @memcpy(i8** %81, i8* %6, i32 8)
store i8* %76, i8** %3
%83 = call i8* @mem_acquire(i8** %2)
%84 = icmp eq i8* %83, null
br i1 %84, label %88, label %104
85: ; preds = %88
%86 = add nsw i32 %89, 1
%87 = icmp eq i32 %86, 9
br i1 %87, label %97, label %88
88: ; preds = %80, %85
%89 = phi i32 [ %86, %85 ], [ -1, %80 ]
%90 = load i8*, i8** %3
%91 = call i32 @memcpy(i8** %3, i8* %90, i32 8)
%92 = call i32 @mem_release(i8* %90, i8** %2)
%93 = load i8*, i8** %2
%94 = call i32 @mem_free_count_get(i8* %93)
%95 = add nsw i32 %89, 2
%96 = icmp eq i32 %95, %94
br i1 %96, label %85, label %104
97: ; preds = %85
%98 = load i8*, i8** %2
%99 = icmp eq i8* %90, %98
br i1 %99, label %100, label %104
100: ; preds = %97
%101 = call i32 @mem_free_count_get(i8* %90)
%102 = icmp eq i32 %101, 10
%103 = select i1 %102, i32 0, i32 6
br label %104
104: ; preds = %88, %12, %17, %24, %31, %38, %45, %52, %59, %66, %73, %100, %97, %80, %0
%105 = phi i32 [ 1, %0 ], [ 3, %80 ], [ 5, %97 ], [ %103, %100 ], [ 2, %73 ], [ 2, %66 ], [ 2, %59 ], [ 2, %52 ], [ 2, %45 ], [ 2, %38 ], [ 2, %31 ], [ 2, %24 ], [ 2, %17 ], [ 2, %12 ], [ 4, %88 ]
ret i32 %105
}