#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 rlimit {
  int rlim_cur;
  int rlim_max;
};

/* Variables and functions */
int /*<<< orphan*/ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ setrlimit(int, struct rlimit *);
int expand(const char *what, int op, int amax) {
  struct rlimit rl;
  int max = amax;
  int ocur;
  getrlimit(op, &rl);
  ocur = rl.rlim_cur;
  if (rl.rlim_cur < max) {
    if (rl.rlim_max < max)
      max = rl.rlim_max;
    rl.rlim_cur = max;
    rl.rlim_max = max;
    setrlimit(op, &rl);
    getrlimit(op, &rl);
  }
  return rl.rlim_cur;
}


x86 assembly (clang, -O0):
<expand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <getrlimit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    118c <expand+0x6c>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1168 <expand+0x48>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1030 <setrlimit@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <getrlimit@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rsp,%rsi
mov    %ebx,%edi
call   1040 <getrlimit@plt>
mov    (%rsp),%eax
cmp    %ebp,%eax
jge    1162 <expand+0x42>
mov    0x4(%rsp),%eax
cmp    %ebp,%eax
cmovl  %eax,%ebp
mov    %ebp,(%rsp)
mov    %ebp,0x4(%rsp)
mov    %rsp,%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <setrlimit@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1040 <getrlimit@plt>
mov    (%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
define i32 @expand(i8* nocapture readnone %0, i32 %1, i32 %2) {
%4 = alloca %struct.rlimit
%5 = bitcast %struct.rlimit* %4 to i8*
%6 = call i32 @getrlimit(i32 %1, %struct.rlimit* %4)
%7 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp slt i32 %8, %2
br i1 %9, label %10, label %18
10: ; preds = %3
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 1
%12 = load i32, i32* %11
%13 = icmp slt i32 %12, %2
%14 = select i1 %13, i32 %12, i32 %2
store i32 %14, i32* %7
store i32 %14, i32* %11
%15 = call i32 @setrlimit(i32 %1, %struct.rlimit* %4)
%16 = call i32 @getrlimit(i32 %1, %struct.rlimit* %4)
%17 = load i32, i32* %7
br label %18
18: ; preds = %10, %3
%19 = phi i32 [ %17, %10 ], [ %8, %3 ]
ret i32 %19
}