#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 /*<<< orphan*/ free(char *);
unsigned int iDoRemoteFunc(unsigned char *, unsigned int, int);
unsigned char iGetParaInt(int /*<<< orphan*/);
char *malloc(int);
unsigned int sprintf(char *, char *, int, unsigned char);
int /*<<< orphan*/ vWriteLogTxt(char *, unsigned int);
unsigned char _ucRcAsyncSetPort(unsigned char ucPortNo) {
  unsigned int uiDataLen, uiRet;
  char *psFunCall = malloc(20);
  uiDataLen = sprintf(psFunCall, "%u(%u)", 1015, ucPortNo);
  uiRet = iDoRemoteFunc((unsigned char *)psFunCall, uiDataLen, 1);
  free(psFunCall);
  if (uiRet) {
    vWriteLogTxt("_ucRcAsyncSetPort iDoRemoteFunc ret = %d", uiRet);
    return ucPortNo;
  }
  return iGetParaInt(0);
}


x86 assembly (clang, -O0):
<_ucRcAsyncSetPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x3f7,%edx
movzbl -0x2(%rbp),%ecx
call   1080 <sprintf@plt>
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x1,%edx
call   1070 <iDoRemoteFunc@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0xc(%rbp)
je     11d9 <_ucRcAsyncSetPort+0x79>
mov    -0xc(%rbp),%esi
lea    0xe3e(%rip),%rdi
call   1050 <vWriteLogTxt@plt>
mov    -0x2(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    11e3 <_ucRcAsyncSetPort+0x83>
xor    %edi,%edi
call   1040 <iGetParaInt@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ucRcAsyncSetPort>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe85(%rip),%rsi
mov    %rax,%rdi
mov    $0x3f7,%edx
mov    %r14d,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1070 <iDoRemoteFunc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     11be <_ucRcAsyncSetPort+0x5e>
lea    0xe58(%rip),%rdi
mov    %ebp,%esi
call   1050 <vWriteLogTxt@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <iGetParaInt@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%u(%u)\00"
@.str.1 = [41 x i8] c"_ucRcAsyncSetPort iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAsyncSetPort(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8 %0, i8* %3
%7 = call i8* @malloc(i32 20)
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = load i8, i8* %3
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 1015, i8 zeroext %9)
store i32 %10, i32* %4
%11 = load i8*, i8** %6
%12 = load i32, i32* %4
%13 = call i32 @iDoRemoteFunc(i8* %11, i32 %12, i32 1)
store i32 %13, i32* %5
%14 = load i8*, i8** %6
%15 = call i32 @free(i8* %14)
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %1
%19 = load i32, i32* %5
%20 = call i32 @vWriteLogTxt(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i8, i8* %3
store i8 %21, i8* %2
br label %24
22: ; preds = %1
%23 = call zeroext i8 @iGetParaInt(i32 0)
store i8 %23, i8* %2
br label %24
24: ; preds = %22, %18
%25 = load i8, i8* %2
ret i8 %25
}

LLVM IR (-O2):
@.str = [7 x i8] c"%u(%u)\00"
@.str.1 = [41 x i8] c"_ucRcAsyncSetPort iDoRemoteFunc ret = %d\00"
define zeroext i8 @_ucRcAsyncSetPort(i8 zeroext %0) {
%2 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%3 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 1015, i8 zeroext %0)
%4 = tail call i32 @iDoRemoteFunc(i8* %2, i32 %3, i32 1)
%5 = tail call i32 @free(i8* %2)
%6 = icmp eq i32 %4, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @vWriteLogTxt(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %11
9: ; preds = %1
%10 = tail call zeroext i8 @iGetParaInt(i32 0)
br label %11
11: ; preds = %9, %7
%12 = phi i8 [ %0, %7 ], [ %10, %9 ]
ret i8 %12
}