#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
unsigned int fv_encode_elem_header(int elem_type, int wall_info[]) {
  unsigned int header;
  int i, nfaces;
  switch (elem_type) {
  case 1:
    header = (1 << (6 * 3));
    nfaces = 4;
    break;
  case 2:
    header = (4 << (6 * 3));
    nfaces = 6;
    break;
  case 3:
    header = (3 << (6 * 3));
    nfaces = 5;
    break;
  case 4:
    header = (2 << (6 * 3));
    nfaces = 5;
    break;
  default:
    fprintf(stderr, "ERROR:  Unknown element type\n");
    return 0;
  }
  for (i = 0; i < nfaces; i++) {
    unsigned int u = wall_info[i];
    if (u > (07u)) {
      fprintf(stderr, "ERROR:  Bad wall value\n");
      return 0;
    }
    header |= (u << (i * 3));
  }
  return header;
}


x86 assembly (clang, -O0):
<fv_encode_elem_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     1194 <fv_encode_elem_header+0x84>
mov    -0x28(%rbp),%rax
lea    0xec1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x40000,-0x14(%rbp)
movl   $0x4,-0x1c(%rbp)
jmp    11b5 <fv_encode_elem_header+0xa5>
movl   $0x100000,-0x14(%rbp)
movl   $0x6,-0x1c(%rbp)
jmp    11b5 <fv_encode_elem_header+0xa5>
movl   $0xc0000,-0x14(%rbp)
movl   $0x5,-0x1c(%rbp)
jmp    11b5 <fv_encode_elem_header+0xa5>
movl   $0x80000,-0x14(%rbp)
movl   $0x5,-0x1c(%rbp)
jmp    11b5 <fv_encode_elem_header+0xa5>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1224 <fv_encode_elem_header+0x114>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    121e <fv_encode_elem_header+0x10e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x7,-0x20(%rbp)
jbe    1201 <fv_encode_elem_header+0xf1>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1224 <fv_encode_elem_header+0x114>
mov    -0x20(%rbp),%eax
imul   $0x3,-0x18(%rbp),%ecx
shl    %cl,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bc <fv_encode_elem_header+0xac>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fv_encode_elem_header>:
push   %rax
add    $0xffffffff,%edi
cmp    $0x3,%edi
ja     115a <fv_encode_elem_header+0x4a>
movslq %edi,%rcx
lea    0xf15(%rip),%rax
mov    (%rax,%rcx,4),%eax
lea    0xf1b(%rip),%rdx
mov    (%rdx,%rcx,8),%r9
xor    %ecx,%ecx
lea    0xee4(%rip),%r8
xor    %edx,%edx
nopl   0x0(%rax)
mov    (%rsi,%rdx,4),%edi
cmp    $0x7,%edi
ja     1161 <fv_encode_elem_header+0x51>
shl    %cl,%edi
or     %edi,%eax
add    $0x1,%rdx
add    $0x3,%ecx
cmp    %rdx,%r9
jne    1140 <fv_encode_elem_header+0x30>
pop    %rcx
ret
lea    0xe9f(%rip),%r8
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    %r8,%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"ERROR: Unknown element type\0A\00"
@.str.1 = [24 x i8] c"ERROR: Bad wall value\0A\00"
define i32 @fv_encode_elem_header(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%10 = load i32, i32* %4
switch i32 %10, label %15 [
i32 1, label %11
i32 2, label %12
i32 3, label %13
i32 4, label %14
]
11: ; preds = %2
store i32 262144, i32* %6
store i32 4, i32* %8
br label %18
12: ; preds = %2
store i32 1048576, i32* %6
store i32 6, i32* %8
br label %18
13: ; preds = %2
store i32 786432, i32* %6
store i32 5, i32* %8
br label %18
14: ; preds = %2
store i32 524288, i32* %6
store i32 5, i32* %8
br label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %46
18: ; preds = %14, %13, %12, %11
store i32 0, i32* %7
br label %19
19: ; preds = %41, %18
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %44
23: ; preds = %19
%24 = load i32*, i32** %5
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp ugt i32 %29, 7
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %46
34: ; preds = %23
%35 = load i32, i32* %9
%36 = load i32, i32* %7
%37 = mul nsw i32 %36, 3
%38 = shl i32 %35, %37
%39 = load i32, i32* %6
%40 = or i32 %39, %38
store i32 %40, i32* %6
br label %41
41: ; preds = %34
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %19
44: ; preds = %19
%45 = load i32, i32* %6
store i32 %45, i32* %3
br label %46
46: ; preds = %44, %31, %15
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"ERROR: Unknown element type\0A\00"
@.str.1 = [24 x i8] c"ERROR: Bad wall value\0A\00"
@switch.table.fv_encode_elem_header = [4 x i32] [i32 262144, i32 1048576, i32 786432, i32 524288]
@switch.table.fv_encode_elem_header.2 = [4 x i64] [i64 4, i64 6, i64 5, i64 5]
define i32 @fv_encode_elem_header(i32 %0, i32* nocapture %1) {
%3 = add i32 %0, -1
%4 = icmp ult i32 %3, 4
br i1 %4, label %5, label %25
5: ; preds = %2
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.fv_encode_elem_header, i64 0, i64 %6
%8 = load i32, i32* %7
%9 = sext i32 %3 to i64
%10 = getelementptr inbounds [4 x i64], [4 x i64]* @switch.table.fv_encode_elem_header.2, i64 0, i64 %9
%11 = load i64, i64* %10
br label %12
12: ; preds = %5, %18
%13 = phi i64 [ 0, %5 ], [ %23, %18 ]
%14 = phi i32 [ %8, %5 ], [ %22, %18 ]
%15 = getelementptr inbounds i32, i32* %1, i64 %13
%16 = load i32, i32* %15
%17 = icmp ugt i32 %16, 7
br i1 %17, label %25, label %18
18: ; preds = %12
%19 = trunc i64 %13 to i32
%20 = mul i32 %19, 3
%21 = shl i32 %16, %20
%22 = or i32 %21, %14
%23 = add nuw nsw i64 %13, 1
%24 = icmp eq i64 %23, %11
br i1 %24, label %29, label %12
25: ; preds = %12, %2
%26 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %12 ]
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* %26)
br label %29
29: ; preds = %18, %25
%30 = phi i32 [ 0, %25 ], [ %22, %18 ]
ret i32 %30
}