#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 */
char *malloc(size_t);
int send_msg(int, char *, size_t);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int send_acknack(int fd, int error_code, const char *error_msg) {
  char *msg = 0;
  size_t msg_len = 0;
  if (error_code) {
    msg_len = strlen(error_msg) + 4;
    msg = malloc((msg_len + 1) * sizeof(char));
    msg[0] = '1';
    msg[1] = '.';
    msg[2] = '1';
    msg[3] = '.';
    strcpy(msg + 5, error_msg);
  } else {
    msg = "1.0";
    msg_len = 3;
  }
  return send_msg(fd, msg, msg_len);
}


x86 assembly (clang, -O0):
<send_acknack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11c8 <send_acknack+0x88>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x4,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x31,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x2e,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x31,0x2(%rax)
mov    -0x18(%rbp),%rax
movb   $0x2e,0x3(%rax)
mov    -0x18(%rbp),%rdi
add    $0x5,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11db <send_acknack+0x9b>
lea    0xe31(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x3,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <send_msg@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_acknack>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
test   %esi,%esi
je     1180 <send_acknack+0x40>
mov    %rdx,%rbp
mov    %rdx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
lea    0x4(%rdi),%r15
add    $0x5,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
movl   $0x2e312e31,(%rax)
lea    0x5(%rax),%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
jmp    118d <send_acknack+0x4d>
mov    $0x3,%r15d
lea    0xe73(%rip),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <send_msg@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"1.0\00"
define i32 @send_acknack(i32 %0, i32 %1, i8* %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %2)
%7 = add nsw i32 %6, 4
%8 = sext i32 %7 to i64
%9 = add nsw i64 %8, 1
%10 = tail call i8* @malloc(i64 %9)
store i8 49, i8* %10
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8 46, i8* %11
%12 = getelementptr inbounds i8, i8* %10, i64 2
store i8 49, i8* %12
%13 = getelementptr inbounds i8, i8* %10, i64 3
store i8 46, i8* %13
%14 = getelementptr inbounds i8, i8* %10, i64 5
%15 = tail call i32 @strcpy(i8* %14, i8* %2)
br label %16
16: ; preds = %3, %5
%17 = phi i8* [ %10, %5 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %3 ]
%18 = phi i64 [ %8, %5 ], [ 3, %3 ]
%19 = tail call i32 @send_msg(i32 %0, i8* %17, i64 %18)
ret i32 %19
}