#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 job_ipl_tape_data {
  int dummy;
};
struct component_loc {
  int dummy;
};

/* Variables and functions */
int check_component_address_data(struct component_loc *, int, char *);
int finalize_component_address_data(struct component_loc *, int);
int /*<<< orphan*/ free(struct component_loc *);
int get_ipl_tape_components(struct job_ipl_tape_data *, struct component_loc **,
                            int *);
int /*<<< orphan*/ sort_cl_array(struct component_loc *, int);
int finalize_ipl_tape_address_data(struct job_ipl_tape_data *ipl_tape,
                                   char *name) {
  struct component_loc *cl;
  int num;
  int rc;
  rc = get_ipl_tape_components(ipl_tape, &cl, &num);
  if (rc)
    return rc;
  sort_cl_array(cl, num);
  rc = check_component_address_data(cl, num, name);
  if (rc)
    goto out_free;
  rc = finalize_component_address_data(cl, num);
out_free:
  free(cl);
  return rc;
}


x86 assembly (clang, -O0):
<finalize_ipl_tape_address_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <get_ipl_tape_components@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1189 <finalize_ipl_tape_address_data+0x39>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <finalize_ipl_tape_address_data+0x85>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <sort_cl_array@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <check_component_address_data@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     11b7 <finalize_ipl_tape_address_data+0x67>
jmp    11c6 <finalize_ipl_tape_address_data+0x76>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <finalize_component_address_data@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finalize_ipl_tape_address_data>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <get_ipl_tape_components@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11ad <finalize_ipl_tape_address_data+0x5d>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
call   1060 <sort_cl_array@plt>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    %rbx,%rdx
call   1040 <check_component_address_data@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11a3 <finalize_ipl_tape_address_data+0x53>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
call   1070 <finalize_component_address_data@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.job_ipl_tape_data = type { i32 }
%struct.component_loc = type { i32 }
define i32 @finalize_ipl_tape_address_data(%struct.job_ipl_tape_data* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.job_ipl_tape_data*
%5 = alloca i8*
%6 = alloca %struct.component_loc*
%7 = alloca i32
%8 = alloca i32
store %struct.job_ipl_tape_data* %0, %struct.job_ipl_tape_data** %4
store i8* %1, i8** %5
%9 = load %struct.job_ipl_tape_data*, %struct.job_ipl_tape_data** %4
%10 = call i32 @get_ipl_tape_components(%struct.job_ipl_tape_data* %9, %struct.component_loc** %6, i32* %7)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %8
store i32 %14, i32* %3
br label %34
15: ; preds = %2
%16 = load %struct.component_loc*, %struct.component_loc** %6
%17 = load i32, i32* %7
%18 = call i32 @sort_cl_array(%struct.component_loc* %16, i32 %17)
%19 = load %struct.component_loc*, %struct.component_loc** %6
%20 = load i32, i32* %7
%21 = load i8*, i8** %5
%22 = call i32 @check_component_address_data(%struct.component_loc* %19, i32 %20, i8* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %15
br label %30
26: ; preds = %15
%27 = load %struct.component_loc*, %struct.component_loc** %6
%28 = load i32, i32* %7
%29 = call i32 @finalize_component_address_data(%struct.component_loc* %27, i32 %28)
store i32 %29, i32* %8
br label %30
30: ; preds = %26, %25
%31 = load %struct.component_loc*, %struct.component_loc** %6
%32 = call i32 @free(%struct.component_loc* %31)
%33 = load i32, i32* %8
store i32 %33, i32* %3
br label %34
34: ; preds = %30, %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.job_ipl_tape_data = type { i32 }
%struct.component_loc = type { i32 }
define i32 @finalize_ipl_tape_address_data(%struct.job_ipl_tape_data* %0, i8* %1) {
%3 = alloca %struct.component_loc*
%4 = alloca i32
%5 = bitcast %struct.component_loc** %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @get_ipl_tape_components(%struct.job_ipl_tape_data* %0, %struct.component_loc** %3, i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %2
%10 = load %struct.component_loc*, %struct.component_loc** %3
%11 = load i32, i32* %4
%12 = call i32 @sort_cl_array(%struct.component_loc* %10, i32 %11)
%13 = load %struct.component_loc*, %struct.component_loc** %3
%14 = load i32, i32* %4
%15 = call i32 @check_component_address_data(%struct.component_loc* %13, i32 %14, i8* %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = load %struct.component_loc*, %struct.component_loc** %3
%19 = load i32, i32* %4
%20 = call i32 @finalize_component_address_data(%struct.component_loc* %18, i32 %19)
br label %21
21: ; preds = %9, %17
%22 = phi i32 [ %15, %9 ], [ %20, %17 ]
%23 = load %struct.component_loc*, %struct.component_loc** %3
%24 = call i32 @free(%struct.component_loc* %23)
br label %25
25: ; preds = %2, %21
%26 = phi i32 [ %22, %21 ], [ %7, %2 ]
ret i32 %26
}