#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*/ uint32_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ send_tris(char *, int /*<<< orphan*/);
size_t snprintf(char *, size_t, char *, char const *, char const *,
                char const *);
size_t strlen(char const *);
int32_t socket_ctrl(const char *group, const char *socket, const char *data,
                    uint32_t pulse_len) {
  size_t s;
  size_t n;
  char codeword[13];
  s = strlen(group) + strlen(socket) + strlen(data);
  n = snprintf(codeword, s + 1, "%s%s%s", group, socket, data);
  if (n != s) {
    return -1;
  }
  send_tris(codeword, pulse_len);
  return 0;
}


x86 assembly (clang, -O0):
<socket_ctrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
lea    -0x45(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xe5f(%rip),%rdx
call   1040 <snprintf@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     11c4 <socket_ctrl+0x94>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <socket_ctrl+0xa7>
lea    -0x45(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <send_tris@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_ctrl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
add    %rbp,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%rbp
lea    (%rax,%rbx,1),%rsi
add    $0x1,%rsi
lea    0xe85(%rip),%rdx
lea    0xb(%rsp),%rdi
mov    %r13,%rcx
mov    %r12,%r8
mov    %r15,%r9
call   1040 <snprintf@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
cmp    %rbp,%rcx
jne    11aa <socket_ctrl+0x7a>
lea    0xb(%rsp),%rdi
mov    %r14d,%esi
call   1050 <send_tris@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s%s%s\00"
define i32 @socket_ctrl(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca [13 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
%15 = load i8*, i8** %7
%16 = call i64 @strlen(i8* %15)
%17 = add i64 %14, %16
%18 = load i8*, i8** %8
%19 = call i64 @strlen(i8* %18)
%20 = add i64 %17, %19
store i64 %20, i64* %10
%21 = getelementptr inbounds [13 x i8], [13 x i8]* %12, i64 0, i64 0
%22 = load i64, i64* %10
%23 = add i64 %22, 1
%24 = load i8*, i8** %6
%25 = load i8*, i8** %7
%26 = load i8*, i8** %8
%27 = call i64 @snprintf(i8* %21, i64 %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25, i8* %26)
store i64 %27, i64* %11
%28 = load i64, i64* %11
%29 = load i64, i64* %10
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %4
store i32 -1, i32* %5
br label %36
32: ; preds = %4
%33 = getelementptr inbounds [13 x i8], [13 x i8]* %12, i64 0, i64 0
%34 = load i32, i32* %9
%35 = call i32 @send_tris(i8* %33, i32 %34)
store i32 0, i32* %5
br label %36
36: ; preds = %32, %31
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s%s%s\00"
define i32 @socket_ctrl(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [13 x i8]
%6 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = add i64 %8, %7
%10 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%11 = add i64 %9, %10
%12 = add i64 %11, 1
%13 = call i64 @snprintf(i8* %6, i64 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2)
%14 = icmp eq i64 %13, %11
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 @send_tris(i8* %6, i32 %3)
br label %17
17: ; preds = %4, %15
%18 = phi i32 [ 0, %15 ], [ -1, %4 ]
ret i32 %18
}