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

/* Variables and functions */
scalar_t__ send_command_to_variable_server(int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, double);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int set_cycle(int socket, double period) {
  char cmd[512];
  const char *prefix = "trick.var_cycle(";
  char per[128];
  const char *suffix = ")";
  snprintf(per, 128, "%lf", period);
  if (sizeof(cmd) < (strlen(prefix) + strlen(per) + strlen(suffix) + 1)) {
    return -1;
  } else {
    strncpy(cmd, prefix, sizeof(cmd));
    strncat(cmd, per, (sizeof(cmd) - strlen(cmd) - 1));
    strncat(cmd, suffix, (sizeof(cmd) - strlen(cmd) - 1));
    if (send_command_to_variable_server(socket, cmd) < 0) {
      return -1;
    } else {
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<set_cycle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2d0,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
lea    0xe96(%rip),%rax
mov    %rax,-0x218(%rbp)
lea    0xe99(%rip),%rax
mov    %rax,-0x2a8(%rbp)
lea    -0x2a0(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    $0x80,%esi
lea    0xe7c(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x218(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2b0(%rbp)
lea    -0x2a0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2b0(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2ac(%rbp)
mov    -0x2a8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2ac(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    $0x200,%eax
cmp    %rcx,%rax
jae    1200 <set_cycle+0xb0>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <set_cycle+0x18c>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x2d0(%rbp)
lea    -0x2a0(%rbp),%rax
mov    %rax,-0x2c8(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2d0(%rbp),%rdi
mov    -0x2c8(%rbp),%rsi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1060 <strncat@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x2c0(%rbp)
mov    -0x2a8(%rbp),%rax
mov    %rax,-0x2b8(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c0(%rbp),%rdi
mov    -0x2b8(%rbp),%rsi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1060 <strncat@plt>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
call   1070 <send_command_to_variable_server@plt>
cmp    $0x0,%rax
jge    12d5 <set_cycle+0x185>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <set_cycle+0x18c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_cycle>:
push   %rbp
push   %r14
push   %rbx
sub    $0x280,%rsp
mov    %edi,%r14d
lea    0xeae(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1050 <snprintf@plt>
lea    0xe84(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xe7d(%rip),%rdi
call   1040 <strlen@plt>
add    %ebp,%ebx
lea    (%rax,%rbx,1),%ecx
add    $0xfffffe00,%ecx
mov    $0xffffffff,%eax
cmp    $0xfffffdff,%ecx
jb     1216 <set_cycle+0xc6>
lea    0xe48(%rip),%rsi
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1ff,%ebp
mov    $0x1ff,%edx
sub    %eax,%edx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
lea    0xe14(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <strncat@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1070 <send_command_to_variable_server@plt>
sar    $0x3f,%rax
add    $0x280,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"trick.var_cycle(\00"
@.str.1 = [2 x i8] c")\00"
@.str.2 = [4 x i8] c"%lf\00"
define i32 @set_cycle(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca [128 x i8]
%9 = alloca i8*
store i32 %0, i32* %4
store double %1, double* %5
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%11 = load double, double* %5
%12 = call i32 @snprintf(i8* %10, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %11)
%13 = load i8*, i8** %7
%14 = call i32 @strlen(i8* %13)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %14, %16
%18 = load i8*, i8** %9
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %17, %19
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = icmp ult i64 512, %22
br i1 %23, label %24, label %25
24: ; preds = %2
store i32 -1, i32* %3
br label %53
25: ; preds = %2
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%27 = load i8*, i8** %7
%28 = call i32 @strncpy(i8* %26, i8* %27, i32 512)
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = sext i32 %32 to i64
%34 = sub i64 512, %33
%35 = sub i64 %34, 1
%36 = trunc i64 %35 to i32
%37 = call i32 @strncat(i8* %29, i8* %30, i32 %36)
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%39 = load i8*, i8** %9
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = sext i32 %41 to i64
%43 = sub i64 512, %42
%44 = sub i64 %43, 1
%45 = trunc i64 %44 to i32
%46 = call i32 @strncat(i8* %38, i8* %39, i32 %45)
%47 = load i32, i32* %4
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%49 = call i64 @send_command_to_variable_server(i32 %47, i8* %48)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %25
store i32 -1, i32* %3
br label %53
52: ; preds = %25
store i32 0, i32* %3
br label %53
53: ; preds = %52, %51, %24
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [17 x i8] c"trick.var_cycle(\00"
@.str.1 = [2 x i8] c")\00"
@.str.2 = [4 x i8] c"%lf\00"
define i32 @set_cycle(i32 %0, double %1) {
%3 = alloca [512 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %1)
%8 = call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @strlen(i8* %6)
%10 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = add i32 %8, -512
%12 = add i32 %11, %9
%13 = add i32 %12, %10
%14 = icmp ult i32 %13, -513
br i1 %14, label %26, label %15
15: ; preds = %2
%16 = call i32 @strncpy(i8* %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 512)
%17 = call i32 @strlen(i8* %5)
%18 = sub i32 511, %17
%19 = call i32 @strncat(i8* %5, i8* %6, i32 %18)
%20 = call i32 @strlen(i8* %5)
%21 = sub i32 511, %20
%22 = call i32 @strncat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = call i64 @send_command_to_variable_server(i32 %0, i8* %5)
%24 = ashr i64 %23, 63
%25 = trunc i64 %24 to i32
br label %26
26: ; preds = %15, %2
%27 = phi i32 [ -1, %2 ], [ %25, %15 ]
ret i32 %27
}