#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 createChainStruct(char *, int, int, int, int);
int /*<<< orphan*/ enableChain(int);
int /*<<< orphan*/ log_err(char *, char *, int, int);
int createChain(char *addr, int Uport, int Rport, int enabled,
                int retryInterval) {
  int chainID = createChainStruct(addr, Uport, Rport, enabled, retryInterval);
  if (chainID == -1) {
    log_err("Creation of chain structure failed for %s port %d, %d", addr,
            Uport, Rport);
    return -1;
  }
  if (enabled == 1 && chainID >= 0)
    enableChain(chainID);
  return chainID;
}


x86 assembly (clang, -O0):
<createChain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1040 <createChainStruct@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    118e <createChain+0x5e>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe83(%rip),%rdi
call   1050 <log_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <createChain+0x80>
cmpl   $0x1,-0x1c(%rbp)
jne    11aa <createChain+0x7a>
cmpl   $0x0,-0x24(%rbp)
jl     11aa <createChain+0x7a>
mov    -0x24(%rbp),%edi
call   1030 <enableChain@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createChain>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%r12
call   1040 <createChainStruct@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1161 <createChain+0x31>
cmp    $0x1,%ebp
jne    1176 <createChain+0x46>
test   %ebx,%ebx
js     1176 <createChain+0x46>
mov    %ebx,%edi
call   1030 <enableChain@plt>
jmp    1176 <createChain+0x46>
lea    0xe98(%rip),%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1050 <log_err@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"Creation of chain structure failed for %s port %d, %d\00"
define i32 @createChain(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%13 = load i8*, i8** %7
%14 = load i32, i32* %8
%15 = load i32, i32* %9
%16 = load i32, i32* %10
%17 = load i32, i32* %11
%18 = call i32 @createChainStruct(i8* %13, i32 %14, i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %12
%19 = load i32, i32* %12
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %26
21: ; preds = %5
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = call i32 @log_err(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %23, i32 %24)
store i32 -1, i32* %6
br label %37
26: ; preds = %5
%27 = load i32, i32* %10
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* %12
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %12
%34 = call i32 @enableChain(i32 %33)
br label %35
35: ; preds = %32, %29, %26
%36 = load i32, i32* %12
store i32 %36, i32* %6
br label %37
37: ; preds = %35, %21
%38 = load i32, i32* %6
ret i32 %38
}

LLVM IR (-O2):
@.str = [54 x i8] c"Creation of chain structure failed for %s port %d, %d\00"
define i32 @createChain(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32 @createChainStruct(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @log_err(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i32 %2)
br label %16
10: ; preds = %5
%11 = icmp eq i32 %3, 1
%12 = icmp sgt i32 %6, -1
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @enableChain(i32 %6)
br label %16
16: ; preds = %10, %14, %8
ret i32 %6
}