#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 sb {
  int dummy;
};
struct block_segment {
  int dummy;
};

/* Variables and functions */
int balloc_find(struct sb *, struct block_segment *, int, int *,
                unsigned int *);
int balloc_use(struct sb *, struct block_segment *, int);
int balloc_segs(struct sb *sb, struct block_segment *seg, int maxsegs,
                int *segs, unsigned *blocks) {
  int err = balloc_find(sb, seg, maxsegs, segs, blocks);
  if (!err)
    err = balloc_use(sb, seg, *segs);
  return err;
}


x86 assembly (clang, -O0):
<balloc_segs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1040 <balloc_find@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1176 <balloc_segs+0x56>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1030 <balloc_use@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<balloc_segs>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <balloc_find@plt>
test   %eax,%eax
je     113d <balloc_segs+0x1d>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%r14),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <balloc_use@plt>

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

LLVM IR (-O2):
%struct.sb = type { i32 }
%struct.block_segment = type { i32 }
define i32 @balloc_segs(%struct.sb* %0, %struct.block_segment* %1, i32 %2, i32* %3, i32* %4) {
%6 = tail call i32 @balloc_find(%struct.sb* %0, %struct.block_segment* %1, i32 %2, i32* %3, i32* %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* %3
%10 = tail call i32 @balloc_use(%struct.sb* %0, %struct.block_segment* %1, i32 %9)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ %6, %5 ], [ %10, %8 ]
ret i32 %12
}