#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*/ load_sign(char const *, int, int, char *);
int load_u32(char const *, int, int);
int /*<<< orphan*/ strcmp(char *, char const *);
int icc_tag(const char *icc, int length, const char *tag, int *offset,
            int *el_length) {
  int tag_count = load_u32(icc, length, 128);
  int t;
  for (t = 0; t < tag_count; t++) {
    char tag_signature[5];
    load_sign(icc, length, 128 + 4 + 12 * t, tag_signature);
    if (!strcmp(tag_signature, tag)) {
      if (offset)
        *offset = load_u32(icc, length, 128 + 4 + 12 * t + 4);
      if (el_length)
        *el_length = load_u32(icc, length, 128 + 4 + 12 * t + 4 * 2);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<icc_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x80,%edx
call   1030 <load_u32@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1219 <icc_tag+0xe9>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
imul   $0xc,-0x38(%rbp),%edx
add    $0x84,%edx
lea    -0x3d(%rbp),%rcx
call   1040 <load_sign@plt>
lea    -0x3d(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1206 <icc_tag+0xd6>
cmpq   $0x0,-0x28(%rbp)
je     11ce <icc_tag+0x9e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
imul   $0xc,-0x38(%rbp),%edx
add    $0x84,%edx
add    $0x4,%edx
call   1030 <load_u32@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     11fa <icc_tag+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
imul   $0xc,-0x38(%rbp),%edx
add    $0x84,%edx
add    $0x8,%edx
call   1030 <load_u32@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1220 <icc_tag+0xf0>
jmp    120b <icc_tag+0xdb>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1166 <icc_tag+0x36>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<icc_tag>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%r13
mov    $0x80,%edx
call   1030 <load_u32@plt>
mov    %eax,%r15d
xor    %eax,%eax
test   %r15d,%r15d
jle    11e4 <icc_tag+0xb4>
mov    %rbp,(%rsp)
mov    %r14,0x8(%rsp)
mov    $0x8c,%ebp
lea    0x13(%rsp),%r14
nopl   0x0(%rax,%rax,1)
lea    -0x8(%rbp),%edx
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r14,%rcx
call   1040 <load_sign@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11ad <icc_tag+0x7d>
add    $0xc,%ebp
add    $0xffffffff,%r15d
jne    1180 <icc_tag+0x50>
xor    %eax,%eax
jmp    11e4 <icc_tag+0xb4>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     11c6 <icc_tag+0x96>
lea    -0x4(%rbp),%edx
mov    %r13,%rdi
mov    %r12d,%esi
call   1030 <load_u32@plt>
mov    %eax,(%rbx)
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     11df <icc_tag+0xaf>
mov    %r13,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
call   1030 <load_u32@plt>
mov    %eax,(%rbx)
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @icc_tag(i8* %0, i32 %1, i8* nocapture %2, i32* writeonly %3, i32* writeonly %4) {
%6 = alloca [5 x i8]
%7 = tail call i32 @load_u32(i8* %0, i32 %1, i32 128)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %32
9: ; preds = %5
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
br label %11
11: ; preds = %9, %29
%12 = phi i32 [ 0, %9 ], [ %30, %29 ]
%13 = mul nuw nsw i32 %12, 12
%14 = add nuw nsw i32 %13, 132
%15 = call i32 @load_sign(i8* %0, i32 %1, i32 %14, i8* %10)
%16 = call i32 @strcmp(i8* %10, i8* dereferenceable(1) %2)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %11
%19 = icmp eq i32* %3, null
br i1 %19, label %23, label %20
20: ; preds = %18
%21 = add nuw nsw i32 %13, 136
%22 = call i32 @load_u32(i8* %0, i32 %1, i32 %21)
store i32 %22, i32* %3
br label %23
23: ; preds = %20, %18
%24 = icmp eq i32* %4, null
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = add nuw nsw i32 %13, 140
%27 = call i32 @load_u32(i8* %0, i32 %1, i32 %26)
store i32 %27, i32* %4
br label %28
28: ; preds = %23, %25
br label %32
29: ; preds = %11
%30 = add nuw nsw i32 %12, 1
%31 = icmp eq i32 %30, %7
br i1 %31, label %32, label %11
32: ; preds = %29, %5, %28
%33 = phi i32 [ 1, %28 ], [ 0, %5 ], [ 0, %29 ]
ret i32 %33
}