#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 */

/* Variables and functions */
int maxflow_scratch_size(int);
int /*<<< orphan*/ maxflow_setup_backedges(int, int const *, int *);
int maxflow_with_scratch(void *, int, int, int, int, int const *, int *,
                         int const *, int *, int *);
int /*<<< orphan*/ sfree(int *);
int *smalloc(int);
int maxflow(int nv, int source, int sink, int ne, const int *edges,
            const int *capacity, int *flow, int *cut) {
  void *scratch;
  int *backedges;
  int size;
  int ret;
  size = ne * sizeof(int) + maxflow_scratch_size(nv);
  backedges = smalloc(size);
  if (!backedges)
    return -1;
  scratch = backedges + ne;
  maxflow_setup_backedges(ne, edges, backedges);
  ret = maxflow_with_scratch(scratch, nv, source, sink, ne, edges, backedges,
                             capacity, flow, cut);
  sfree(backedges);
  return ret;
}


x86 assembly (clang, -O0):
<maxflow>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <maxflow_scratch_size@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
call   1070 <smalloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11bb <maxflow+0x6b>
movl   $0xffffffff,-0xc(%rbp)
jmp    122d <maxflow+0xdd>
mov    -0x40(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1050 <maxflow_setup_backedges@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x28(%rbp),%r9
mov    -0x40(%rbp),%rbx
mov    -0x30(%rbp),%r11
mov    0x10(%rbp),%r10
mov    0x18(%rbp),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1060 <maxflow_with_scratch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <sfree@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<maxflow>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%rbp
mov    %r8,%r15
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %esi,0xc(%rsp)
mov    %edi,%r14d
call   1040 <maxflow_scratch_size@plt>
lea    (%rax,%r12,4),%edi
call   1070 <smalloc@plt>
test   %rax,%rax
je     11da <maxflow+0x8a>
mov    %rax,%rbx
movslq %r12d,%rax
mov    %rbp,0x10(%rsp)
mov    %r13d,%ebp
lea    (%rbx,%rax,4),%r13
mov    %r12d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <maxflow_setup_backedges@plt>
mov    %r13,%rdi
mov    %r14d,%esi
mov    0xc(%rsp),%edx
mov    %ebp,%ecx
mov    %r12d,%r8d
mov    %r15,%r9
push   0x58(%rsp)
push   0x58(%rsp)
push   0x20(%rsp)
push   %rbx
call   1060 <maxflow_with_scratch@plt>
add    $0x20,%rsp
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <sfree@plt>
mov    %ebp,%eax
jmp    11df <maxflow+0x8f>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @maxflow(i32 %0, i32 %1, i32 %2, i32 %3, i32* %4, i32* %5, i32* %6, i32* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i8*
%19 = alloca i32*
%20 = alloca i32
%21 = alloca i32
store i32 %0, i32* %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32* %4, i32** %14
store i32* %5, i32** %15
store i32* %6, i32** %16
store i32* %7, i32** %17
%22 = load i32, i32* %13
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 4
%25 = load i32, i32* %10
%26 = call i32 @maxflow_scratch_size(i32 %25)
%27 = sext i32 %26 to i64
%28 = add i64 %24, %27
%29 = trunc i64 %28 to i32
store i32 %29, i32* %20
%30 = load i32, i32* %20
%31 = call i32* @smalloc(i32 %30)
store i32* %31, i32** %19
%32 = load i32*, i32** %19
%33 = icmp ne i32* %32, null
br i1 %33, label %35, label %34
34: ; preds = %8
store i32 -1, i32* %9
br label %59
35: ; preds = %8
%36 = load i32*, i32** %19
%37 = load i32, i32* %13
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = bitcast i32* %39 to i8*
store i8* %40, i8** %18
%41 = load i32, i32* %13
%42 = load i32*, i32** %14
%43 = load i32*, i32** %19
%44 = call i32 @maxflow_setup_backedges(i32 %41, i32* %42, i32* %43)
%45 = load i8*, i8** %18
%46 = load i32, i32* %10
%47 = load i32, i32* %11
%48 = load i32, i32* %12
%49 = load i32, i32* %13
%50 = load i32*, i32** %14
%51 = load i32*, i32** %19
%52 = load i32*, i32** %15
%53 = load i32*, i32** %16
%54 = load i32*, i32** %17
%55 = call i32 @maxflow_with_scratch(i8* %45, i32 %46, i32 %47, i32 %48, i32 %49, i32* %50, i32* %51, i32* %52, i32* %53, i32* %54)
store i32 %55, i32* %21
%56 = load i32*, i32** %19
%57 = call i32 @sfree(i32* %56)
%58 = load i32, i32* %21
store i32 %58, i32* %9
br label %59
59: ; preds = %35, %34
%60 = load i32, i32* %9
ret i32 %60
}

LLVM IR (-O2):
define i32 @maxflow(i32 %0, i32 %1, i32 %2, i32 %3, i32* %4, i32* %5, i32* %6, i32* %7) {
%9 = shl i32 %3, 2
%10 = tail call i32 @maxflow_scratch_size(i32 %0)
%11 = add i32 %10, %9
%12 = tail call i32* @smalloc(i32 %11)
%13 = icmp eq i32* %12, null
br i1 %13, label %21, label %14
14: ; preds = %8
%15 = sext i32 %3 to i64
%16 = getelementptr inbounds i32, i32* %12, i64 %15
%17 = bitcast i32* %16 to i8*
%18 = tail call i32 @maxflow_setup_backedges(i32 %3, i32* %4, i32* %12)
%19 = tail call i32 @maxflow_with_scratch(i8* %17, i32 %0, i32 %1, i32 %2, i32 %3, i32* %4, i32* %12, i32* %5, i32* %6, i32* %7)
%20 = tail call i32 @sfree(i32* %12)
br label %21
21: ; preds = %8, %14
%22 = phi i32 [ %19, %14 ], [ -1, %8 ]
ret i32 %22
}