#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 iso_util_tag_magic(int tag_type, char **tag_magic, int *len, int flag) {
  static char *magic[] = {
      "", "libisofs_checksum_tag_v1", "libisofs_sb_checksum_tag_v1",
      "libisofs_tree_checksum_tag_v1", "libisofs_rlsb32_checksum_tag_v1"};
  static int magic_len[] = {0, 24, 27, 29, 31};
  static int magic_max = 4;
  *tag_magic = NULL;
  *len = 0;
  if (tag_type < 0 || tag_type > magic_max)
    return 0xE830FFF8;
  *tag_magic = magic[tag_type];
  *len = magic_len[tag_type];
  return magic_max;
}


x86 assembly (clang, -O0):
<iso_util_tag_magic>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
cmpl   $0x0,-0x8(%rbp)
jl     1140 <iso_util_tag_magic+0x40>
mov    -0x8(%rbp),%eax
cmp    0x2f3a(%rip),%eax
jle    114c <iso_util_tag_magic+0x4c>
movl   $0xe830fff8,-0x4(%rbp)
jmp    117f <iso_util_tag_magic+0x7f>
movslq -0x8(%rbp),%rcx
lea    0x2ed9(%rip),%rax
mov    (%rax,%rcx,8),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movslq -0x8(%rbp),%rcx
lea    0x2ef3(%rip),%rax
mov    (%rax,%rcx,4),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2ef8(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<iso_util_tag_magic>:
movq   $0x0,(%rsi)
movl   $0x0,(%rdx)
mov    $0xe830fff8,%eax
cmp    $0x4,%edi
ja     113b <iso_util_tag_magic+0x3b>
mov    %edi,%eax
lea    0xee0(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
mov    %rdi,(%rsi)
lea    0xeef(%rip),%rcx
mov    (%rcx,%rax,4),%eax
mov    %eax,(%rdx)
mov    $0x4,%eax
ret

LLVM IR (-O0):
@iso_util_tag_magic.magic = internal global [5 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i32 0, i32 0)]
@.str = [1 x i8] zeroinitializer
@.str.1 = [25 x i8] c"libisofs_checksum_tag_v1\00"
@.str.2 = [28 x i8] c"libisofs_sb_checksum_tag_v1\00"
@.str.3 = [30 x i8] c"libisofs_tree_checksum_tag_v1\00"
@.str.4 = [32 x i8] c"libisofs_rlsb32_checksum_tag_v1\00"
@iso_util_tag_magic.magic_len = internal global [5 x i32] [i32 0, i32 24, i32 27, i32 29, i32 31]
@iso_util_tag_magic.magic_max = internal global i32 4
define i32 @iso_util_tag_magic(i32 %0, i8** %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%10 = load i8**, i8*** %7
store i8* null, i8** %10
%11 = load i32*, i32** %8
store i32 0, i32* %11
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %4
%15 = load i32, i32* %6
%16 = load i32, i32* @iso_util_tag_magic.magic_max
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14, %4
store i32 -399441928, i32* %5
br label %31
19: ; preds = %14
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [5 x i8*], [5 x i8*]* @iso_util_tag_magic.magic, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %7
store i8* %23, i8** %24
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [5 x i32], [5 x i32]* @iso_util_tag_magic.magic_len, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = load i32*, i32** %8
store i32 %28, i32* %29
%30 = load i32, i32* @iso_util_tag_magic.magic_max
store i32 %30, i32* %5
br label %31
31: ; preds = %19, %18
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@reltable.iso_util_tag_magic = internal unnamed_addr constant [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([1 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.iso_util_tag_magic to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.iso_util_tag_magic to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.iso_util_tag_magic to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([30 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.iso_util_tag_magic to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.iso_util_tag_magic to i64)) to i32)]
@.str = [1 x i8] zeroinitializer
@.str.1 = [25 x i8] c"libisofs_checksum_tag_v1\00"
@.str.2 = [28 x i8] c"libisofs_sb_checksum_tag_v1\00"
@.str.3 = [30 x i8] c"libisofs_tree_checksum_tag_v1\00"
@.str.4 = [32 x i8] c"libisofs_rlsb32_checksum_tag_v1\00"
@iso_util_tag_magic.magic_len = internal unnamed_addr constant [5 x i32] [i32 0, i32 24, i32 27, i32 29, i32 31]
define i32 @iso_util_tag_magic(i32 %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2, i32 %3) {
store i8* null, i8** %1
store i32 0, i32* %2
%5 = icmp ugt i32 %0, 4
br i1 %5, label %12, label %6
6: ; preds = %4
%7 = zext i32 %0 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.iso_util_tag_magic to i8*), i64 %8)
store i8* %9, i8** %1
%10 = getelementptr inbounds [5 x i32], [5 x i32]* @iso_util_tag_magic.magic_len, i64 0, i64 %7
%11 = load i32, i32* %10
store i32 %11, i32* %2
br label %12
12: ; preds = %4, %6
%13 = phi i32 [ 4, %6 ], [ -399441928, %4 ]
ret i32 %13
}