#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ netplot_enable_status_messages(int);
int netplot_init(int);
int send_command_expect_ok(int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int netplot_set_plot_type(int server_connection_index, int plot_type,
                          char *plot_title) {
  int rc;
  char buffer[256];
  memset(buffer, 0, 256);
  if (plot_type == 1) {
    strncpy(buffer, "set graph=time\n", 256);
  } else if (plot_type == 2) {
    strncpy(buffer, "set graph=bar\n", 256);
  } else if (plot_type == 3) {
    strncpy(buffer, "set graph=xy\n", 256);
  } else if (plot_type == 4) {
    strncpy(buffer, "set graph=dial\n", 256);
  } else {
    return -2;
  }
  rc = send_command_expect_ok(server_connection_index, buffer);
  if (rc == 0) {
    if (strlen(plot_title) > 0) {
      memset(buffer, 0, 256);
      snprintf(buffer, 256, "set plot_title=%s\n", plot_title);
      rc = send_command_expect_ok(server_connection_index, buffer);
    }
    if (rc == 0) {
      rc = netplot_init(server_connection_index);
      if (rc == 0) {
        netplot_enable_status_messages(1);
      }
    }
  }
  return rc;
}


x86 assembly (clang, -O0):
<netplot_set_plot_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
cmpl   $0x1,-0xc(%rbp)
jne    11bf <netplot_set_plot_type+0x4f>
lea    -0x120(%rbp),%rdi
lea    0xe50(%rip),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    124f <netplot_set_plot_type+0xdf>
cmpl   $0x2,-0xc(%rbp)
jne    11e6 <netplot_set_plot_type+0x76>
lea    -0x120(%rbp),%rdi
lea    0xe39(%rip),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    124a <netplot_set_plot_type+0xda>
cmpl   $0x3,-0xc(%rbp)
jne    120d <netplot_set_plot_type+0x9d>
lea    -0x120(%rbp),%rdi
lea    0xe21(%rip),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    1245 <netplot_set_plot_type+0xd5>
cmpl   $0x4,-0xc(%rbp)
jne    1234 <netplot_set_plot_type+0xc4>
lea    -0x120(%rbp),%rdi
lea    0xe08(%rip),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    1240 <netplot_set_plot_type+0xd0>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12f8 <netplot_set_plot_type+0x188>
jmp    1245 <netplot_set_plot_type+0xd5>
jmp    124a <netplot_set_plot_type+0xda>
jmp    124f <netplot_set_plot_type+0xdf>
mov    -0x8(%rbp),%edi
lea    -0x120(%rbp),%rsi
call   1080 <send_command_expect_ok@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12f2 <netplot_set_plot_type+0x182>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    12bf <netplot_set_plot_type+0x14f>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x100,%esi
lea    0xd95(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x120(%rbp),%rsi
call   1080 <send_command_expect_ok@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12ed <netplot_set_plot_type+0x17d>
mov    -0x8(%rbp),%edi
call   1070 <netplot_init@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12e8 <netplot_set_plot_type+0x178>
mov    $0x1,%edi
call   1090 <netplot_enable_status_messages@plt>
jmp    12ed <netplot_set_plot_type+0x17d>
jmp    12f2 <netplot_set_plot_type+0x182>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netplot_set_plot_type>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
add    $0xffffffff,%ebp
mov    $0xfffffffe,%eax
cmp    $0x3,%ebp
ja     11cd <netplot_set_plot_type+0x5d>
movslq %ebp,%rax
lea    0xea8(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1080 <send_command_expect_ok@plt>
test   %eax,%eax
je     11d9 <netplot_set_plot_type+0x69>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    121d <netplot_set_plot_type+0xad>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0xe3e(%rip),%rdx
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1080 <send_command_expect_ok@plt>
test   %eax,%eax
jne    11cd <netplot_set_plot_type+0x5d>
mov    %ebx,%edi
call   1070 <netplot_init@plt>
test   %eax,%eax
jne    11cd <netplot_set_plot_type+0x5d>
mov    $0x1,%edi
call   1090 <netplot_enable_status_messages@plt>
xor    %eax,%eax
jmp    11cd <netplot_set_plot_type+0x5d>

LLVM IR (-O0):
@.str = [16 x i8] c"set graph=time\0A\00"
@.str.1 = [15 x i8] c"set graph=bar\0A\00"
@.str.2 = [14 x i8] c"set graph=xy\0A\00"
@.str.3 = [16 x i8] c"set graph=dial\0A\00"
@.str.4 = [19 x i8] c"set plot_title=%s\0A\00"
define i32 @netplot_set_plot_type(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [256 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 256)
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%16 = call i32 @strncpy(i8* %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 256)
br label %39
17: ; preds = %3
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%22 = call i32 @strncpy(i8* %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 256)
br label %38
23: ; preds = %17
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%28 = call i32 @strncpy(i8* %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 256)
br label %37
29: ; preds = %23
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 4
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%34 = call i32 @strncpy(i8* %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 256)
br label %36
35: ; preds = %29
store i32 -2, i32* %4
br label %72
36: ; preds = %32
br label %37
37: ; preds = %36, %26
br label %38
38: ; preds = %37, %20
br label %39
39: ; preds = %38, %14
%40 = load i32, i32* %5
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%42 = call i32 @send_command_expect_ok(i32 %40, i8* %41)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %70
45: ; preds = %39
%46 = load i8*, i8** %7
%47 = call i64 @strlen(i8* %46)
%48 = icmp sgt i64 %47, 0
br i1 %48, label %49, label %58
49: ; preds = %45
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%51 = call i32 @memset(i8* %50, i32 0, i32 256)
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%53 = load i8*, i8** %7
%54 = call i32 @snprintf(i8* %52, i32 256, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = load i32, i32* %5
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%57 = call i32 @send_command_expect_ok(i32 %55, i8* %56)
store i32 %57, i32* %8
br label %58
58: ; preds = %49, %45
%59 = load i32, i32* %8
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %69
61: ; preds = %58
%62 = load i32, i32* %5
%63 = call i32 @netplot_init(i32 %62)
store i32 %63, i32* %8
%64 = load i32, i32* %8
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 @netplot_enable_status_messages(i32 1)
br label %68
68: ; preds = %66, %61
br label %69
69: ; preds = %68, %58
br label %70
70: ; preds = %69, %39
%71 = load i32, i32* %8
store i32 %71, i32* %4
br label %72
72: ; preds = %70, %35
%73 = load i32, i32* %4
ret i32 %73
}

LLVM IR (-O2):
@.str = [16 x i8] c"set graph=time\0A\00"
@.str.1 = [15 x i8] c"set graph=bar\0A\00"
@.str.2 = [14 x i8] c"set graph=xy\0A\00"
@.str.3 = [16 x i8] c"set graph=dial\0A\00"
@.str.4 = [19 x i8] c"set plot_title=%s\0A\00"
@reltable.netplot_set_plot_type = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.netplot_set_plot_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.netplot_set_plot_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.netplot_set_plot_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.netplot_set_plot_type to i64)) to i32)]
define i32 @netplot_set_plot_type(i32 %0, i32 %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 256)
%7 = add i32 %1, -1
%8 = icmp ult i32 %7, 4
br i1 %8, label %9, label %29
9: ; preds = %3
%10 = sext i32 %7 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.netplot_set_plot_type to i8*), i64 %11)
%13 = call i32 @strncpy(i8* %5, i8* %12, i32 256)
%14 = call i32 @send_command_expect_ok(i32 %0, i8* %5)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %9
%17 = call i64 @strlen(i8* dereferenceable(1) %2)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = call i32 @memset(i8* %5, i32 0, i32 256)
%21 = call i32 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%22 = call i32 @send_command_expect_ok(i32 %0, i8* %5)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %16, %19
%25 = call i32 @netplot_init(i32 %0)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @netplot_enable_status_messages(i32 1)
br label %29
29: ; preds = %3, %9, %24, %27, %19
%30 = phi i32 [ -2, %3 ], [ 0, %27 ], [ %25, %24 ], [ %22, %19 ], [ %14, %9 ]
ret i32 %30
}