#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 alpar_send(int, unsigned short, unsigned int, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getchar();
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int sscanf(char const *, char *, unsigned short *, unsigned int *);
void isend(int fd, const char *command_str) {
  unsigned short int control;
  unsigned int length;
  char *data;
  data = NULL;
  if (sscanf(command_str, "%*s %hx %x", &control, &length) != 2) {
    printf("scanf failed..less arguements ?");
    return;
  }
  if (length) {
    int i;
    data = (char *)malloc(length * sizeof(char));
    if (!data) {
      printf("No memory\n");
      return;
    }
    for (i = 0; i < length; i++) {
      printf("data[%d]=", i);
      scanf("%x", &data[i]);
    }
    getchar();
  }
  printf("control=%hx,length=%x\n", control, length);
  if (length) {
    int i;
    for (i = 0; i < length; i++)
      printf("data[%d]=%u(0x%x)\n", i, (unsigned char)data[i],
             (unsigned char)data[i]);
  }
  if (alpar_send(fd, control, length, data) == -1)
    perror("send failed");
  if (data)
    free(data);
}


x86 assembly (clang, -O0):
<isend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x12(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1080 <sscanf@plt>
cmp    $0x2,%eax
je     11cb <isend+0x4b>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1302 <isend+0x182>
cmpl   $0x0,-0x18(%rbp)
je     1255 <isend+0xd5>
mov    -0x18(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1205 <isend+0x85>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1302 <isend+0x182>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    124e <isend+0xce>
mov    -0x24(%rbp),%esi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
lea    0xdcd(%rip),%rdi
call   1090 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120c <isend+0x8c>
mov    $0x0,%al
call   1060 <getchar@plt>
movzwl -0x12(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     12c3 <isend+0x143>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    12be <isend+0x13e>
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    127b <isend+0xfb>
jmp    12c3 <isend+0x143>
mov    -0x4(%rbp),%edi
mov    -0x12(%rbp),%ax
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
movzwl %ax,%esi
call   1040 <alpar_send@plt>
cmp    $0xffffffff,%eax
jne    12ee <isend+0x16e>
lea    0xd81(%rip),%rdi
call   10a0 <perror@plt>
cmpq   $0x0,-0x20(%rbp)
je     1302 <isend+0x182>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %edi,%r14d
lea    0xe58(%rip),%rsi
lea    0x6(%rsp),%rdx
mov    %rsp,%rcx
mov    %rax,%rdi
call   1090 <sscanf@plt>
cmp    $0x2,%eax
jne    1220 <isend+0x90>
mov    (%rsp),%edi
xor    %ebp,%ebp
test   %edi,%edi
je     1233 <isend+0xa3>
call   1080 <malloc@plt>
test   %rax,%rax
je     12a6 <isend+0x116>
mov    %rax,%r13
cmpl   $0x0,(%rsp)
je     1214 <isend+0x84>
lea    0xe47(%rip),%r15
lea    0xe1d(%rip),%r12
xor    %ebx,%ebx
nopl   (%rax)
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    (%rbx,%r13,1),%rsi
mov    %r12,%rdi
call   10a0 <scanf@plt>
add    $0x1,%rbx
mov    (%rsp),%eax
cmp    %rax,%rbx
jb     11f0 <isend+0x60>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    (%rsp),%edx
jmp    1238 <isend+0xa8>
lea    0xde4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12b2 <isend+0x122>
xor    %edx,%edx
xor    %r13d,%r13d
movzwl 0x6(%rsp),%esi
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,(%rsp)
je     1280 <isend+0xf0>
lea    0xdf4(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbx,1),%ecx
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ecx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
mov    (%rsp),%ebp
cmp    %rbp,%rbx
jb     1260 <isend+0xd0>
movzwl 0x6(%rsp),%esi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %r13,%rcx
call   1040 <alpar_send@plt>
cmp    $0xffffffff,%eax
je     12c1 <isend+0x131>
test   %r13,%r13
je     12b2 <isend+0x122>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    12b2 <isend+0x122>
lea    0xdbe(%rip),%rdi
call   1050 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd97(%rip),%rdi
call   10b0 <perror@plt>
test   %r13,%r13
jne    129c <isend+0x10c>
jmp    12b2 <isend+0x122>

LLVM IR (-O0):
@.str = [11 x i8] c"%*s %hx %x\00"
@.str.1 = [32 x i8] c"scanf failed..less arguements ?\00"
@.str.2 = [11 x i8] c"No memory\0A\00"
@.str.3 = [10 x i8] c"data[%d]=\00"
@.str.4 = [3 x i8] c"%x\00"
@.str.5 = [23 x i8] c"control=%hx,length=%x\0A\00"
@.str.6 = [19 x i8] c"data[%d]=%u(0x%x)\0A\00"
@.str.7 = [12 x i8] c"send failed\00"
define void @isend(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i8* null, i8** %7
%10 = load i8*, i8** %4
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i16* %5, i32* %6)
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %93
15: ; preds = %2
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %47
18: ; preds = %15
%19 = load i32, i32* %6
%20 = zext i32 %19 to i64
%21 = mul i64 %20, 1
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %29, label %27
27: ; preds = %18
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %93
29: ; preds = %18
store i32 0, i32* %8
br label %30
30: ; preds = %42, %29
%31 = load i32, i32* %8
%32 = load i32, i32* %6
%33 = icmp ult i32 %31, %32
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load i32, i32* %8
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = load i8*, i8** %7
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %34
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %30
45: ; preds = %30
%46 = call i32 (...) @getchar()
br label %47
47: ; preds = %45, %15
%48 = load i16, i16* %5
%49 = zext i16 %48 to i32
%50 = load i32, i32* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %49, i32 %50)
%52 = load i32, i32* %6
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %78
54: ; preds = %47
store i32 0, i32* %9
br label %55
55: ; preds = %74, %54
%56 = load i32, i32* %9
%57 = load i32, i32* %6
%58 = icmp ult i32 %56, %57
br i1 %58, label %59, label %77
59: ; preds = %55
%60 = load i32, i32* %9
%61 = load i8*, i8** %7
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = load i8*, i8** %7
%68 = load i32, i32* %9
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %60, i32 %66, i32 %72)
br label %74
74: ; preds = %59
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 1
store i32 %76, i32* %9
br label %55
77: ; preds = %55
br label %78
78: ; preds = %77, %47
%79 = load i32, i32* %3
%80 = load i16, i16* %5
%81 = load i32, i32* %6
%82 = load i8*, i8** %7
%83 = call i32 @alpar_send(i32 %79, i16 zeroext %80, i32 %81, i8* %82)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %87
85: ; preds = %78
%86 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %87
87: ; preds = %85, %78
%88 = load i8*, i8** %7
%89 = icmp ne i8* %88, null
br i1 %89, label %90, label %93
90: ; preds = %87
%91 = load i8*, i8** %7
%92 = call i32 @free(i8* %91)
br label %93
93: ; preds = %13, %27, %90, %87
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"%*s %hx %x\00"
@.str.1 = [32 x i8] c"scanf failed..less arguements ?\00"
@.str.3 = [10 x i8] c"data[%d]=\00"
@.str.4 = [3 x i8] c"%x\00"
@.str.5 = [23 x i8] c"control=%hx,length=%x\0A\00"
@.str.6 = [19 x i8] c"data[%d]=%u(0x%x)\0A\00"
@.str.7 = [12 x i8] c"send failed\00"
@str = [10 x i8] c"No memory\00"
define void @isend(i32 %0, i8* nocapture %1) {
%3 = alloca i16
%4 = alloca i32
%5 = bitcast i16* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i16* %3, i32* %4)
%8 = icmp eq i32 %7, 2
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %66
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %36, label %14
14: ; preds = %11
%15 = call i64 @malloc(i32 %12)
%16 = inttoptr i64 %15 to i8*
%17 = icmp eq i64 %15, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %33, label %23
21: ; preds = %14
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %66
23: ; preds = %18, %23
%24 = phi i64 [ %29, %23 ], [ 0, %18 ]
%25 = trunc i64 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds i8, i8* %16, i64 %24
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = add nuw nsw i64 %24, 1
%30 = load i32, i32* %4
%31 = zext i32 %30 to i64
%32 = icmp ult i64 %29, %31
br i1 %32, label %23, label %33
33: ; preds = %23, %18
%34 = call i32 (...) @getchar()
%35 = load i32, i32* %4
br label %36
36: ; preds = %33, %11
%37 = phi i32 [ %35, %33 ], [ 0, %11 ]
%38 = phi i8* [ %16, %33 ], [ null, %11 ]
%39 = load i16, i16* %3
%40 = zext i16 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %40, i32 %37)
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 0
br i1 %43, label %55, label %44
44: ; preds = %36, %44
%45 = phi i64 [ %51, %44 ], [ 0, %36 ]
%46 = getelementptr inbounds i8, i8* %38, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = trunc i64 %45 to i32
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %49, i32 %48, i32 %48)
%51 = add nuw nsw i64 %45, 1
%52 = load i32, i32* %4
%53 = zext i32 %52 to i64
%54 = icmp ult i64 %51, %53
br i1 %54, label %44, label %55
55: ; preds = %44, %36
%56 = phi i32 [ 0, %36 ], [ %52, %44 ]
%57 = load i16, i16* %3
%58 = call i32 @alpar_send(i32 %0, i16 zeroext %57, i32 %56, i8* %38)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %62
62: ; preds = %60, %55
%63 = icmp eq i8* %38, null
br i1 %63, label %66, label %64
64: ; preds = %62
%65 = call i32 @free(i8* %38)
br label %66
66: ; preds = %21, %62, %64, %9
ret void
}