#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 ModbusRequestToRespond(unsigned char *, int, unsigned char *);
char *gettext(char *);
int /*<<< orphan*/ printf(char *, ...);
int AskAndAnswer(unsigned char *Ask, int LgtAsk, unsigned char *Answer) {
  int LgtModbusReply = 0;
  int LgtHeaderReply = 0;
  int i;
  printf("-> ");
  for (i = 0; i < LgtAsk; i++) {
    if (i == 7)
      printf("- ");
    printf("%02X ", Ask[i]);
  }
  printf("\n");
  LgtModbusReply = ModbusRequestToRespond(&Ask[7], LgtAsk, &Answer[7]);
  if (LgtModbusReply > 0) {
    Answer[LgtHeaderReply++] = Ask[0];
    Answer[LgtHeaderReply++] = Ask[1];
    Answer[LgtHeaderReply++] = 0;
    Answer[LgtHeaderReply++] = 0;
    Answer[LgtHeaderReply++] = (unsigned char)((LgtModbusReply + 1) >> 8);
    Answer[LgtHeaderReply++] = (unsigned char)(LgtModbusReply + 1);
    Answer[LgtHeaderReply++] = 1;
    printf(gettext("INFO CLASSICLADDER--- MODBUS RESPONSE LGT=%d+%d !\n"),
           LgtHeaderReply, LgtModbusReply);
    printf("<- ");
    for (i = 0; i < LgtHeaderReply + LgtModbusReply; i++) {
      if (i == 7)
        printf("- ");
      printf("%02X ", Answer[i]);
    }
    printf("\n");
  }
  return LgtHeaderReply + LgtModbusReply;
}


x86 assembly (clang, -O0):
<AskAndAnswer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b2 <AskAndAnswer+0x82>
cmpl   $0x7,-0x24(%rbp)
jne    118a <AskAndAnswer+0x5a>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1166 <AskAndAnswer+0x36>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x7,%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
add    $0x7,%rdx
call   1030 <ModbusRequestToRespond@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    132b <AskAndAnswer+0x1fb>
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
sar    $0x8,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
movb   $0x1,(%rax,%rcx,1)
lea    0xd68(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    131d <AskAndAnswer+0x1ed>
cmpl   $0x7,-0x24(%rbp)
jne    12f5 <AskAndAnswer+0x1c5>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12cc <AskAndAnswer+0x19c>
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AskAndAnswer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,0x4(%rsp)
test   %ebp,%ebp
jle    11aa <AskAndAnswer+0x6a>
mov    0x4(%rsp),%ebp
lea    0xeca(%rip),%r12
lea    0xe89(%rip),%r13
xor    %r14d,%r14d
jmp    1198 <AskAndAnswer+0x58>
movzbl (%rbx,%r14,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r14
cmp    %r14,%rbp
je     11aa <AskAndAnswer+0x6a>
cmp    $0x7,%r14
jne    1180 <AskAndAnswer+0x40>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1180 <AskAndAnswer+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x7(%rbx),%rdi
mov    %r15,%rbp
lea    0x7(%r15),%rdx
mov    0x4(%rsp),%esi
call   1040 <ModbusRequestToRespond@plt>
mov    %eax,%r14d
test   %eax,%eax
mov    $0x0,%eax
jle    1289 <AskAndAnswer+0x149>
mov    (%rbx),%al
mov    %al,0x0(%rbp)
mov    0x1(%rbx),%al
mov    %al,0x1(%rbp)
movw   $0x0,0x2(%rbp)
lea    0x1(%r14),%eax
mov    %ah,0x4(%rbp)
mov    %al,0x5(%rbp)
movb   $0x1,0x6(%rbp)
lea    0xe0c(%rip),%rdi
call   1050 <gettext@plt>
xor    %ebp,%ebp
mov    %rax,%rdi
mov    $0x7,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe1f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x6(%r14),%ebx
test   %ebx,%ebx
cmovle %ebp,%ebx
add    $0x1,%ebx
lea    0xe06(%rip),%r13
lea    0xdc5(%rip),%r12
xor    %ebp,%ebp
jmp    1268 <AskAndAnswer+0x128>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r15,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     127a <AskAndAnswer+0x13a>
cmp    $0x7,%rbp
jne    1250 <AskAndAnswer+0x110>
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1250 <AskAndAnswer+0x110>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x7,%eax
add    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"-> \00"
@.str.1 = [3 x i8] c"- \00"
@.str.2 = [6 x i8] c"%02X \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [51 x i8] c"INFO CLASSICLADDER--- MODBUS RESPONSE LGT=%d+%d !\0A\00"
@.str.5 = [4 x i8] c"<- \00"
define i32 @AskAndAnswer(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %9
br label %11
11: ; preds = %28, %3
%12 = load i32, i32* %9
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %31
15: ; preds = %11
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, 7
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = load i8*, i8** %4
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %20
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
br label %11
31: ; preds = %11
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 7
%35 = load i32, i32* %5
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 7
%38 = call i32 @ModbusRequestToRespond(i8* %34, i32 %35, i8* %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %119
41: ; preds = %31
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i64 0
%44 = load i8, i8* %43
%45 = load i8*, i8** %6
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
store i8 %44, i8* %49
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = load i8, i8* %51
%53 = load i8*, i8** %6
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
store i8 %52, i8* %57
%58 = load i8*, i8** %6
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i8, i8* %58, i64 %61
store i8 0, i8* %62
%63 = load i8*, i8** %6
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
store i8 0, i8* %67
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
%70 = ashr i32 %69, 8
%71 = trunc i32 %70 to i8
%72 = load i8*, i8** %6
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
%75 = sext i32 %73 to i64
%76 = getelementptr inbounds i8, i8* %72, i64 %75
store i8 %71, i8* %76
%77 = load i32, i32* %7
%78 = add nsw i32 %77, 1
%79 = trunc i32 %78 to i8
%80 = load i8*, i8** %6
%81 = load i32, i32* %8
%82 = add nsw i32 %81, 1
store i32 %82, i32* %8
%83 = sext i32 %81 to i64
%84 = getelementptr inbounds i8, i8* %80, i64 %83
store i8 %79, i8* %84
%85 = load i8*, i8** %6
%86 = load i32, i32* %8
%87 = add nsw i32 %86, 1
store i32 %87, i32* %8
%88 = sext i32 %86 to i64
%89 = getelementptr inbounds i8, i8* %85, i64 %88
store i8 1, i8* %89
%90 = call i8* @gettext(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%91 = load i32, i32* %8
%92 = load i32, i32* %7
%93 = call i32 (i8*, ...) @printf(i8* %90, i32 %91, i32 %92)
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %9
br label %95
95: ; preds = %114, %41
%96 = load i32, i32* %9
%97 = load i32, i32* %8
%98 = load i32, i32* %7
%99 = add nsw i32 %97, %98
%100 = icmp slt i32 %96, %99
br i1 %100, label %101, label %117
101: ; preds = %95
%102 = load i32, i32* %9
%103 = icmp eq i32 %102, 7
br i1 %103, label %104, label %106
104: ; preds = %101
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %106
106: ; preds = %104, %101
%107 = load i8*, i8** %6
%108 = load i32, i32* %9
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %107, i64 %109
%111 = load i8, i8* %110
%112 = zext i8 %111 to i32
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %112)
br label %114
114: ; preds = %106
%115 = load i32, i32* %9
%116 = add nsw i32 %115, 1
store i32 %116, i32* %9
br label %95
117: ; preds = %95
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %119
119: ; preds = %117, %31
%120 = load i32, i32* %8
%121 = load i32, i32* %7
%122 = add nsw i32 %120, %121
ret i32 %122
}

LLVM IR (-O2):
@.str = [4 x i8] c"-> \00"
@.str.1 = [3 x i8] c"- \00"
@.str.2 = [6 x i8] c"%02X \00"
@.str.4 = [51 x i8] c"INFO CLASSICLADDER--- MODBUS RESPONSE LGT=%d+%d !\0A\00"
@.str.5 = [4 x i8] c"<- \00"
define i32 @AskAndAnswer(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %20
6: ; preds = %3
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %13
%9 = phi i64 [ 0, %6 ], [ %18, %13 ]
%10 = icmp eq i64 %9, 7
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = getelementptr inbounds i8, i8* %0, i64 %9
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %7
br i1 %19, label %20, label %8
20: ; preds = %13, %3
%21 = tail call i32 @putchar(i32 10)
%22 = getelementptr inbounds i8, i8* %0, i64 7
%23 = getelementptr inbounds i8, i8* %2, i64 7
%24 = tail call i32 @ModbusRequestToRespond(i8* %22, i32 %1, i8* %23)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %61
26: ; preds = %20
%27 = load i8, i8* %0
store i8 %27, i8* %2
%28 = getelementptr inbounds i8, i8* %0, i64 1
%29 = load i8, i8* %28
%30 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %29, i8* %30
%31 = getelementptr inbounds i8, i8* %2, i64 2
store i8 0, i8* %31
%32 = getelementptr inbounds i8, i8* %2, i64 3
store i8 0, i8* %32
%33 = add nuw nsw i32 %24, 1
%34 = lshr i32 %33, 8
%35 = trunc i32 %34 to i8
%36 = getelementptr inbounds i8, i8* %2, i64 4
store i8 %35, i8* %36
%37 = trunc i32 %33 to i8
%38 = getelementptr inbounds i8, i8* %2, i64 5
store i8 %37, i8* %38
%39 = getelementptr inbounds i8, i8* %2, i64 6
store i8 1, i8* %39
%40 = tail call i8* @gettext(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %40, i32 7, i32 %24)
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%43 = add nuw i32 %24, 6
%44 = call i32 @llvm.smax.i32(i32 %43, i32 0)
%45 = add nuw i32 %44, 1
%46 = zext i32 %45 to i64
br label %47
47: ; preds = %26, %52
%48 = phi i64 [ 0, %26 ], [ %57, %52 ]
%49 = icmp eq i64 %48, 7
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %52
52: ; preds = %50, %47
%53 = getelementptr inbounds i8, i8* %2, i64 %48
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = add nuw nsw i64 %48, 1
%58 = icmp eq i64 %57, %46
br i1 %58, label %59, label %47
59: ; preds = %52
%60 = tail call i32 @putchar(i32 10)
br label %61
61: ; preds = %59, %20
%62 = phi i32 [ 7, %59 ], [ 0, %20 ]
%63 = add nsw i32 %62, %24
ret i32 %63
}