#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 scalar_t__ addr_mode;

/* Variables and functions */
int /*<<< orphan*/ assert(scalar_t__);
unsigned int _map_mem_addr(unsigned char addr_mode, unsigned int r2,
                           unsigned int r3, unsigned int data) {
  assert(((addr_mode) & (1 << (3))));
  if (((addr_mode) & (1 << (2)))) {
    unsigned int base_addr = r2;
    if (((addr_mode) & (1 << (1)))) {
      if (((addr_mode) & (1 << (0)))) {
        return base_addr + r3;
      } else {
        return base_addr + data;
      }
    } else {
      return base_addr;
    }
  } else {
    return data;
  }
}


x86 assembly (clang, -O0):
<_map_mem_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x8,%eax
movslq %eax,%rdi
call   1030 <assert@plt>
movzbl -0x5(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1193 <_map_mem_addr+0x83>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1188 <_map_mem_addr+0x78>
movzbl -0x5(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     117a <_map_mem_addr+0x6a>
mov    -0x18(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1199 <_map_mem_addr+0x89>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1199 <_map_mem_addr+0x89>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1199 <_map_mem_addr+0x89>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_map_mem_addr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebp
and    $0x8,%edi
call   1030 <assert@plt>
test   $0x4,%bpl
je     114b <_map_mem_addr+0x3b>
test   $0x2,%bpl
jne    113a <_map_mem_addr+0x2a>
mov    %r15d,%ebx
jmp    114b <_map_mem_addr+0x3b>
test   $0x1,%bpl
jne    1145 <_map_mem_addr+0x35>
add    %r15d,%ebx
jmp    114b <_map_mem_addr+0x3b>
add    %r15d,%r14d
mov    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_map_mem_addr(i8 zeroext %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8 %0, i8* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i8, i8* %6
%12 = zext i8 %11 to i32
%13 = and i32 %12, 8
%14 = sext i32 %13 to i64
%15 = call i32 @assert(i64 %14)
%16 = load i8, i8* %6
%17 = zext i8 %16 to i32
%18 = and i32 %17, 4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %41
20: ; preds = %4
%21 = load i32, i32* %7
store i32 %21, i32* %10
%22 = load i8, i8* %6
%23 = zext i8 %22 to i32
%24 = and i32 %23, 2
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %39
26: ; preds = %20
%27 = load i8, i8* %6
%28 = zext i8 %27 to i32
%29 = and i32 %28, 1
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* %10
%33 = load i32, i32* %8
%34 = add i32 %32, %33
store i32 %34, i32* %5
br label %43
35: ; preds = %26
%36 = load i32, i32* %10
%37 = load i32, i32* %9
%38 = add i32 %36, %37
store i32 %38, i32* %5
br label %43
39: ; preds = %20
%40 = load i32, i32* %10
store i32 %40, i32* %5
br label %43
41: ; preds = %4
%42 = load i32, i32* %9
store i32 %42, i32* %5
br label %43
43: ; preds = %41, %39, %35, %31
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
define i32 @_map_mem_addr(i8 zeroext %0, i32 %1, i32 %2, i32 %3) {
%5 = zext i8 %0 to i32
%6 = and i32 %5, 8
%7 = zext i32 %6 to i64
%8 = tail call i32 @assert(i64 %7)
%9 = and i32 %5, 4
%10 = icmp eq i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %4
%12 = and i32 %5, 2
%13 = icmp eq i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = and i32 %5, 1
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = add i32 %2, %1
br label %21
19: ; preds = %14
%20 = add i32 %3, %1
br label %21
21: ; preds = %4, %17, %19, %11
%22 = phi i32 [ %18, %17 ], [ %20, %19 ], [ %1, %11 ], [ %3, %4 ]
ret i32 %22
}