#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 */
struct uio_info_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(struct uio_info_t **);
struct uio_info_t **uio_find_devices();
int uio_get_maxmap(struct uio_info_t *);
unsigned int uio_get_mem_addr(struct uio_info_t *, int);
struct uio_info_t *uio_find_by_base_addr(unsigned int base_addr) {
  struct uio_info_t *info = NULL, **list, **uio_list;
  int mapc, mapnum, found = 0;
  uio_list = uio_find_devices();
  if (!uio_list)
    return NULL;
  for (list = uio_list; *list; list++) {
    struct uio_info_t *candidate = *list;
    mapnum = uio_get_maxmap(candidate);
    for (mapc = 0; mapc < mapnum; mapc++) {
      if (base_addr == uio_get_mem_addr(candidate, mapc)) {
        info = candidate;
        found = 1;
        break;
      }
    }
    if (found)
      break;
  }
  free(uio_list);
  return info;
}


x86 assembly (clang, -O0):
<uio_find_by_base_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
mov    $0x0,%al
call   1040 <uio_find_devices@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117d <uio_find_by_base_addr+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    1239 <uio_find_by_base_addr+0xf9>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1228 <uio_find_by_base_addr+0xe8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <uio_get_maxmap@plt>
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1203 <uio_find_by_base_addr+0xc3>
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <uio_get_mem_addr@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jne    11f0 <uio_find_by_base_addr+0xb0>
mov    -0x40(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1203 <uio_find_by_base_addr+0xc3>
jmp    11f5 <uio_find_by_base_addr+0xb5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b1 <uio_find_by_base_addr+0x71>
cmpl   $0x0,-0x34(%rbp)
je     1212 <uio_find_by_base_addr+0xd2>
jmp    1228 <uio_find_by_base_addr+0xe8>
jmp    1217 <uio_find_by_base_addr+0xd7>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1185 <uio_find_by_base_addr+0x45>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uio_find_by_base_addr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <uio_find_devices@plt>
test   %rax,%rax
je     11b3 <uio_find_by_base_addr+0x73>
mov    %rax,%r14
mov    (%rax),%r12
test   %r12,%r12
je     11a8 <uio_find_by_base_addr+0x68>
mov    %r14,%r13
jmp    117d <uio_find_by_base_addr+0x3d>
nopl   (%rax)
mov    0x8(%r13),%r12
add    $0x8,%r13
test   %r12,%r12
je     11a8 <uio_find_by_base_addr+0x68>
mov    %r12,%rdi
call   1050 <uio_get_maxmap@plt>
test   %eax,%eax
jle    1170 <uio_find_by_base_addr+0x30>
mov    %eax,%ebp
xor    %ebx,%ebx
nopl   (%rax)
mov    %r12,%rdi
mov    %ebx,%esi
call   1060 <uio_get_mem_addr@plt>
cmp    %r15d,%eax
je     11ab <uio_find_by_base_addr+0x6b>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1190 <uio_find_by_base_addr+0x50>
jmp    1170 <uio_find_by_base_addr+0x30>
xor    %r12d,%r12d
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.uio_info_t = type { i32 }
define %struct.uio_info_t* @uio_find_by_base_addr(i32 %0) {
%2 = alloca %struct.uio_info_t*
%3 = alloca i32
%4 = alloca %struct.uio_info_t*
%5 = alloca %struct.uio_info_t**
%6 = alloca %struct.uio_info_t**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.uio_info_t*
store i32 %0, i32* %3
store %struct.uio_info_t* null, %struct.uio_info_t** %4
store i32 0, i32* %9
%11 = call %struct.uio_info_t** (...) @uio_find_devices()
store %struct.uio_info_t** %11, %struct.uio_info_t*** %6
%12 = load %struct.uio_info_t**, %struct.uio_info_t*** %6
%13 = icmp ne %struct.uio_info_t** %12, null
br i1 %13, label %15, label %14
14: ; preds = %1
store %struct.uio_info_t* null, %struct.uio_info_t** %2
br label %54
15: ; preds = %1
%16 = load %struct.uio_info_t**, %struct.uio_info_t*** %6
store %struct.uio_info_t** %16, %struct.uio_info_t*** %5
br label %17
17: ; preds = %47, %15
%18 = load %struct.uio_info_t**, %struct.uio_info_t*** %5
%19 = load %struct.uio_info_t*, %struct.uio_info_t** %18
%20 = icmp ne %struct.uio_info_t* %19, null
br i1 %20, label %21, label %50
21: ; preds = %17
%22 = load %struct.uio_info_t**, %struct.uio_info_t*** %5
%23 = load %struct.uio_info_t*, %struct.uio_info_t** %22
store %struct.uio_info_t* %23, %struct.uio_info_t** %10
%24 = load %struct.uio_info_t*, %struct.uio_info_t** %10
%25 = call i32 @uio_get_maxmap(%struct.uio_info_t* %24)
store i32 %25, i32* %8
store i32 0, i32* %7
br label %26
26: ; preds = %39, %21
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %42
30: ; preds = %26
%31 = load i32, i32* %3
%32 = load %struct.uio_info_t*, %struct.uio_info_t** %10
%33 = load i32, i32* %7
%34 = call i32 @uio_get_mem_addr(%struct.uio_info_t* %32, i32 %33)
%35 = icmp eq i32 %31, %34
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = load %struct.uio_info_t*, %struct.uio_info_t** %10
store %struct.uio_info_t* %37, %struct.uio_info_t** %4
store i32 1, i32* %9
br label %42
38: ; preds = %30
br label %39
39: ; preds = %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %26
42: ; preds = %36, %26
%43 = load i32, i32* %9
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %42
br label %50
46: ; preds = %42
br label %47
47: ; preds = %46
%48 = load %struct.uio_info_t**, %struct.uio_info_t*** %5
%49 = getelementptr inbounds %struct.uio_info_t*, %struct.uio_info_t** %48, i32 1
store %struct.uio_info_t** %49, %struct.uio_info_t*** %5
br label %17
50: ; preds = %45, %17
%51 = load %struct.uio_info_t**, %struct.uio_info_t*** %6
%52 = call i32 @free(%struct.uio_info_t** %51)
%53 = load %struct.uio_info_t*, %struct.uio_info_t** %4
store %struct.uio_info_t* %53, %struct.uio_info_t** %2
br label %54
54: ; preds = %50, %14
%55 = load %struct.uio_info_t*, %struct.uio_info_t** %2
ret %struct.uio_info_t* %55
}

LLVM IR (-O2):
%struct.uio_info_t = type { i32 }
define %struct.uio_info_t* @uio_find_by_base_addr(i32 %0) {
%2 = tail call %struct.uio_info_t** (...) @uio_find_devices()
%3 = icmp eq %struct.uio_info_t** %2, null
br i1 %3, label %26, label %4
4: ; preds = %1
%5 = load %struct.uio_info_t*, %struct.uio_info_t** %2
%6 = icmp eq %struct.uio_info_t* %5, null
br i1 %6, label %23, label %7
7: ; preds = %4, %19
%8 = phi %struct.uio_info_t* [ %21, %19 ], [ %5, %4 ]
%9 = phi %struct.uio_info_t** [ %20, %19 ], [ %2, %4 ]
%10 = tail call i32 @uio_get_maxmap(%struct.uio_info_t* %8)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %14, label %19
12: ; preds = %14
%13 = icmp eq i32 %18, %10
br i1 %13, label %19, label %14
14: ; preds = %7, %12
%15 = phi i32 [ %18, %12 ], [ 0, %7 ]
%16 = tail call i32 @uio_get_mem_addr(%struct.uio_info_t* %8, i32 %15)
%17 = icmp eq i32 %16, %0
%18 = add nuw nsw i32 %15, 1
br i1 %17, label %23, label %12
19: ; preds = %12, %7
%20 = getelementptr inbounds %struct.uio_info_t*, %struct.uio_info_t** %9, i64 1
%21 = load %struct.uio_info_t*, %struct.uio_info_t** %20
%22 = icmp eq %struct.uio_info_t* %21, null
br i1 %22, label %23, label %7
23: ; preds = %19, %14, %4
%24 = phi %struct.uio_info_t* [ null, %4 ], [ %8, %14 ], [ null, %19 ]
%25 = tail call i32 @free(%struct.uio_info_t** %2)
br label %26
26: ; preds = %1, %23
%27 = phi %struct.uio_info_t* [ %24, %23 ], [ null, %1 ]
ret %struct.uio_info_t* %27
}