#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 pci_dev {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ pci_release_region(struct pci_dev *, int);
int pci_request_region(struct pci_dev *, int, char const *);
int pci_request_regions(struct pci_dev *pdev, char const *res_name) {
  int i;
  int tmp;
  {
    i = 0;
    while (i < 6) {
      tmp = pci_request_region(pdev, i, res_name);
      if (tmp) {
        goto err_out;
      }
      i++;
    }
    return (0);
  err_out:
    while (1) {
      i--;
      if (!(i >= 0)) {
        break;
      }
      pci_release_region(pdev, i);
    }
    return (-16);
  }
}


x86 assembly (clang, -O0):
<pci_request_regions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x6,-0x1c(%rbp)
jge    1171 <pci_request_regions+0x51>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <pci_request_region@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1163 <pci_request_regions+0x43>
jmp    117d <pci_request_regions+0x5d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <pci_request_regions+0x17>
movl   $0x0,-0x4(%rbp)
jmp    11b2 <pci_request_regions+0x92>
jmp    1182 <pci_request_regions+0x62>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    119a <pci_request_regions+0x7a>
jmp    11ab <pci_request_regions+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <pci_release_region@plt>
jmp    1182 <pci_request_regions+0x62>
movl   $0xfffffff0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pci_request_regions>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <pci_request_region@plt>
mov    $0xfffffff0,%r14d
test   %eax,%eax
jne    11e3 <pci_request_regions+0xc3>
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1040 <pci_request_region@plt>
test   %eax,%eax
jne    11c2 <pci_request_regions+0xa2>
mov    $0x2,%ebp
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
call   1040 <pci_request_region@plt>
test   %eax,%eax
jne    11c2 <pci_request_regions+0xa2>
mov    $0x3,%ebp
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %r15,%rdx
call   1040 <pci_request_region@plt>
test   %eax,%eax
jne    11c2 <pci_request_regions+0xa2>
mov    $0x4,%ebp
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r15,%rdx
call   1040 <pci_request_region@plt>
test   %eax,%eax
jne    11c2 <pci_request_regions+0xa2>
mov    $0x5,%ebp
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r15,%rdx
call   1040 <pci_request_region@plt>
test   %eax,%eax
je     11f1 <pci_request_regions+0xd1>
add    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x2(%rbp),%esi
mov    %rbx,%rdi
call   1030 <pci_release_region@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     11d0 <pci_request_regions+0xb0>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
jmp    11e3 <pci_request_regions+0xc3>

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

LLVM IR (-O2):
%struct.pci_dev = type { i32 }
define i32 @pci_request_regions(%struct.pci_dev* %0, i8* %1) {
%3 = tail call i32 @pci_request_region(%struct.pci_dev* %0, i32 0, i8* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %27
5: ; preds = %2
%6 = tail call i32 @pci_request_region(%struct.pci_dev* %0, i32 1, i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = tail call i32 @pci_request_region(%struct.pci_dev* %0, i32 2, i8* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = tail call i32 @pci_request_region(%struct.pci_dev* %0, i32 3, i8* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = tail call i32 @pci_request_region(%struct.pci_dev* %0, i32 4, i8* %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 @pci_request_region(%struct.pci_dev* %0, i32 5, i8* %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %17, %14, %11, %8, %5
%21 = phi i32 [ 5, %17 ], [ 4, %14 ], [ 3, %11 ], [ 2, %8 ], [ 1, %5 ]
br label %22
22: ; preds = %20, %22
%23 = phi i32 [ %24, %22 ], [ %21, %20 ]
%24 = add nsw i32 %23, -1
%25 = tail call i32 @pci_release_region(%struct.pci_dev* %0, i32 %24)
%26 = icmp ugt i32 %23, 1
br i1 %26, label %22, label %27
27: ; preds = %22, %17, %2
%28 = phi i32 [ -16, %2 ], [ 0, %17 ], [ -16, %22 ]
ret i32 %28
}