#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ say(int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, unsigned short,
                            unsigned short);
char *strchr(char *, char);
void sayact(int fd, char *addr, int port) {
  unsigned short int lo, hi;
  char buffer[4096], *dot;
  hi = port % 256;
  lo = (port - hi) / 256;
  while ((dot = strchr(addr, '.'))) {
    *dot = ',';
  }
  snprintf(buffer, sizeof(buffer), "PORT %s,%d,%d\r\n", addr, lo, hi);
  say(fd, buffer);
}


x86 assembly (clang, -O0):
<sayact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dx,%ax
mov    %ax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
movzwl -0x18(%rbp),%ecx
sub    %ecx,%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %ax,-0x16(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
je     119a <sayact+0x6a>
mov    -0x1028(%rbp),%rax
movb   $0x2c,(%rax)
jmp    116c <sayact+0x3c>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x16(%rbp),%ax
mov    $0x1000,%esi
lea    0xe4b(%rip),%rdx
movzwl %ax,%r8d
movzwl -0x18(%rbp),%r9d
call   1040 <snprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x1020(%rbp),%rsi
call   1050 <say@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sayact>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xff(%rbp),%eax
test   %edx,%edx
cmovns %edx,%eax
and    $0xffffff00,%eax
mov    %edx,%r15d
sub    %eax,%r15d
mov    %rsi,%rdi
xchg   %ax,%ax
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1177 <sayact+0x47>
movb   $0x2c,(%rax)
mov    %rbx,%rdi
jmp    1160 <sayact+0x30>
movzwl %r15w,%r9d
sub    %r9d,%ebp
lea    0xff(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
shr    $0x8,%eax
movzwl %ax,%r8d
lea    0xe69(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1050 <say@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"PORT %s,%d,%d\0D\0A\00"
define void @sayact(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i16
%8 = alloca i16
%9 = alloca [4096 x i8]
%10 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = srem i32 %11, 256
%13 = trunc i32 %12 to i16
store i16 %13, i16* %8
%14 = load i32, i32* %6
%15 = load i16, i16* %8
%16 = zext i16 %15 to i32
%17 = sub nsw i32 %14, %16
%18 = sdiv i32 %17, 256
%19 = trunc i32 %18 to i16
store i16 %19, i16* %7
br label %20
20: ; preds = %24, %3
%21 = load i8*, i8** %5
%22 = call i8* @strchr(i8* %21, i8 signext 46)
store i8* %22, i8** %10
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = load i8*, i8** %10
store i8 44, i8* %25
br label %20
26: ; preds = %20
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%28 = load i8*, i8** %5
%29 = load i16, i16* %7
%30 = load i16, i16* %8
%31 = call i32 @snprintf(i8* %27, i32 4096, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %28, i16 zeroext %29, i16 zeroext %30)
%32 = load i32, i32* %4
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%34 = call i32 @say(i32 %32, i8* %33)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"PORT %s,%d,%d\0D\0A\00"
define void @sayact(i32 %0, i8* %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = srem i32 %2, 256
%7 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 46)
%8 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %3, %9
%10 = phi i8* [ %11, %9 ], [ %7, %3 ]
store i8 44, i8* %10
%11 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 46)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %9
13: ; preds = %9, %3
%14 = and i32 %6, 65535
%15 = sub nsw i32 %2, %14
%16 = sdiv i32 %15, 256
%17 = trunc i32 %16 to i16
%18 = trunc i32 %6 to i16
%19 = call i32 @snprintf(i8* %5, i32 4096, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1, i16 zeroext %17, i16 zeroext %18)
%20 = call i32 @say(i32 %0, i8* %5)
ret void
}