#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 m_new(int, int);
scalar_t__ m_next(int, int *, void **);
scalar_t__ memcmp(void *, void *, int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ mls(int, int);
int m_lookup_obj(int m, void *obj, int size) {
  int p;
  void *d;
  for (p = -1; m_next(m, &p, &d);)
    if (memcmp(d, obj, size) == 0)
      return p;
  p = m_new(m, 1);
  memcpy(mls(m, p), obj, size);
  return p;
}


x86 assembly (clang, -O0):
<m_lookup_obj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <m_next@plt>
cmp    $0x0,%rax
je     11ad <m_lookup_obj+0x5d>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    11a8 <m_lookup_obj+0x58>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11dc <m_lookup_obj+0x8c>
jmp    1169 <m_lookup_obj+0x19>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1050 <m_new@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1070 <mls@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_lookup_obj>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0xffffffff,0x4(%rsp)
ff
lea    0x4(%rsp),%r15
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <m_next@plt>
test   %rax,%rax
je     11a9 <m_lookup_obj+0x59>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    1180 <m_lookup_obj+0x30>
jmp    11cf <m_lookup_obj+0x7f>
mov    %ebp,%edi
mov    $0x1,%esi
call   1050 <m_new@plt>
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
mov    %eax,%esi
call   1070 <mls@plt>
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
mov    0x4(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @m_lookup_obj(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 -1, i32* %8
br label %10
10: ; preds = %22, %3
%11 = load i32, i32* %5
%12 = call i64 @m_next(i32 %11, i32* %8, i8** %9)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i8*, i8** %9
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = call i64 @memcmp(i8* %15, i8* %16, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = load i32, i32* %8
store i32 %21, i32* %4
br label %33
22: ; preds = %14
br label %10
23: ; preds = %10
%24 = load i32, i32* %5
%25 = call i32 @m_new(i32 %24, i32 1)
store i32 %25, i32* %8
%26 = load i32, i32* %5
%27 = load i32, i32* %8
%28 = call i32 @mls(i32 %26, i32 %27)
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = call i32 @memcpy(i32 %28, i8* %29, i32 %30)
%32 = load i32, i32* %8
store i32 %32, i32* %4
br label %33
33: ; preds = %23, %20
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @m_lookup_obj(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = bitcast i32* %4 to i8*
%7 = bitcast i8** %5 to i8*
store i32 -1, i32* %4
br label %8
8: ; preds = %11, %3
%9 = call i64 @m_next(i32 %0, i32* %4, i8** %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i8*, i8** %5
%13 = call i64 @memcmp(i8* %12, i8* %1, i32 %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %8
15: ; preds = %8
%16 = call i32 @m_new(i32 %0, i32 1)
store i32 %16, i32* %4
%17 = call i32 @mls(i32 %0, i32 %16)
%18 = call i32 @memcpy(i32 %17, i8* %1, i32 %2)
br label %19
19: ; preds = %11, %15
%20 = load i32, i32* %4
ret i32 %20
}