#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 int uint32_t;
struct imd_header {
  int dummy;
};

/* Variables and functions */
struct imd_header *imd_next(struct imd_header *);
int imd_read_type(struct imd_header *);
struct imd_header *imd_find_type(struct imd_header *imd, uint32_t type) {
  for (imd = imd_next(imd); imd_read_type(imd) != 0x640c7fff;
       imd = imd_next(imd))
    if (imd_read_type(imd) == type)
      return imd;
  return NULL;
}


x86 assembly (clang, -O0):
<imd_find_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <imd_next@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <imd_read_type@plt>
cmp    $0x640c7fff,%eax
je     1186 <imd_find_type+0x66>
mov    -0x10(%rbp),%rdi
call   1030 <imd_read_type@plt>
cmp    -0x14(%rbp),%eax
jne    116f <imd_find_type+0x4f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118e <imd_find_type+0x6e>
jmp    1174 <imd_find_type+0x54>
mov    -0x10(%rbp),%rdi
call   1040 <imd_next@plt>
mov    %rax,-0x10(%rbp)
jmp    113c <imd_find_type+0x1c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imd_find_type>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
call   1040 <imd_next@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <imd_read_type@plt>
cmp    $0x640c7fff,%eax
je     1158 <imd_find_type+0x38>
mov    %rbx,%rdi
call   1030 <imd_read_type@plt>
cmp    %ebp,%eax
je     115a <imd_find_type+0x3a>
mov    %rbx,%rdi
jmp    1130 <imd_find_type+0x10>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.imd_header = type { i32 }
define %struct.imd_header* @imd_find_type(%struct.imd_header* %0, i32 %1) {
%3 = alloca %struct.imd_header*
%4 = alloca %struct.imd_header*
%5 = alloca i32
store %struct.imd_header* %0, %struct.imd_header** %4
store i32 %1, i32* %5
%6 = load %struct.imd_header*, %struct.imd_header** %4
%7 = call %struct.imd_header* @imd_next(%struct.imd_header* %6)
store %struct.imd_header* %7, %struct.imd_header** %4
br label %8
8: ; preds = %20, %2
%9 = load %struct.imd_header*, %struct.imd_header** %4
%10 = call i32 @imd_read_type(%struct.imd_header* %9)
%11 = icmp ne i32 %10, 1678540799
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load %struct.imd_header*, %struct.imd_header** %4
%14 = call i32 @imd_read_type(%struct.imd_header* %13)
%15 = load i32, i32* %5
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load %struct.imd_header*, %struct.imd_header** %4
store %struct.imd_header* %18, %struct.imd_header** %3
br label %24
19: ; preds = %12
br label %20
20: ; preds = %19
%21 = load %struct.imd_header*, %struct.imd_header** %4
%22 = call %struct.imd_header* @imd_next(%struct.imd_header* %21)
store %struct.imd_header* %22, %struct.imd_header** %4
br label %8
23: ; preds = %8
store %struct.imd_header* null, %struct.imd_header** %3
br label %24
24: ; preds = %23, %17
%25 = load %struct.imd_header*, %struct.imd_header** %3
ret %struct.imd_header* %25
}

LLVM IR (-O2):
%struct.imd_header = type { i32 }
define %struct.imd_header* @imd_find_type(%struct.imd_header* %0, i32 %1) {
%3 = tail call %struct.imd_header* @imd_next(%struct.imd_header* %0)
%4 = tail call i32 @imd_read_type(%struct.imd_header* %3)
%5 = icmp eq i32 %4, 1678540799
br i1 %5, label %14, label %6
6: ; preds = %2, %10
%7 = phi %struct.imd_header* [ %11, %10 ], [ %3, %2 ]
%8 = tail call i32 @imd_read_type(%struct.imd_header* %7)
%9 = icmp eq i32 %8, %1
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = tail call %struct.imd_header* @imd_next(%struct.imd_header* %7)
%12 = tail call i32 @imd_read_type(%struct.imd_header* %11)
%13 = icmp eq i32 %12, 1678540799
br i1 %13, label %14, label %6
14: ; preds = %6, %10, %2
%15 = phi %struct.imd_header* [ null, %2 ], [ null, %10 ], [ %7, %6 ]
ret %struct.imd_header* %15
}