#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*/ fatalError(char *);
int read(int, int *, int);
int strlen(char *);
int write(int, ...);
int sendResponseToClient(int socketFD, char *answer) {
  int serverResponse = 0;
  int answerLength = strlen(answer) + 1;
  int n = 0;
  if (write(socketFD, &answerLength, 4) == -1)
    fatalError("Response sending error 1");
  n = read(socketFD, &serverResponse, 4);
  if (n != 4 || serverResponse != 0)
    fatalError("Response sending error 2");
  if (answerLength != 1) {
    if ((n = write(socketFD, answer, answerLength)) == -1)
      fatalError("Response sending error 3");
    n = read(socketFD, &serverResponse, 4);
    if (n != 4 || serverResponse != 0)
      fatalError("Response sending error 4");
  }
  return 0;
}


x86 assembly (clang, -O0):
<sendResponseToClient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1194 <sendResponseToClient+0x54>
lea    0xe71(%rip),%rdi
call   1060 <fatalError@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jne    11bc <sendResponseToClient+0x7c>
cmpl   $0x0,-0x14(%rbp)
je     11c8 <sendResponseToClient+0x88>
lea    0xe56(%rip),%rdi
call   1060 <fatalError@plt>
cmpl   $0x1,-0x18(%rbp)
je     1234 <sendResponseToClient+0xf4>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11fb <sendResponseToClient+0xbb>
lea    0xe3c(%rip),%rdi
call   1060 <fatalError@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jne    1223 <sendResponseToClient+0xe3>
cmpl   $0x0,-0x14(%rbp)
je     122f <sendResponseToClient+0xef>
lea    0xe21(%rip),%rdi
call   1060 <fatalError@plt>
jmp    1234 <sendResponseToClient+0xf4>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendResponseToClient>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
movl   $0x0,(%rsp)
mov    %rsi,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1183 <sendResponseToClient+0x43>
lea    0xe82(%rip),%rdi
call   1060 <fatalError@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    119d <sendResponseToClient+0x5d>
cmpl   $0x0,(%rsp)
je     11a9 <sendResponseToClient+0x69>
lea    0xe75(%rip),%rdi
call   1060 <fatalError@plt>
mov    0x4(%rsp),%edx
cmp    $0x1,%edx
je     11f5 <sendResponseToClient+0xb5>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11cf <sendResponseToClient+0x8f>
lea    0xe68(%rip),%rdi
call   1060 <fatalError@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    11e9 <sendResponseToClient+0xa9>
cmpl   $0x0,(%rsp)
je     11f5 <sendResponseToClient+0xb5>
lea    0xe5b(%rip),%rdi
call   1060 <fatalError@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Response sending error 1\00"
@.str.1 = [25 x i8] c"Response sending error 2\00"
@.str.2 = [25 x i8] c"Response sending error 3\00"
@.str.3 = [25 x i8] c"Response sending error 4\00"
define i32 @sendResponseToClient(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
store i32 %10, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %3
%12 = call i32 (i32, ...) @write(i32 %11, i32* %6, i32 4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @fatalError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i32, i32* %3
%18 = call i32 @read(i32 %17, i32* %5, i32 4)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 4
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21, %16
%25 = call i32 @fatalError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %48
29: ; preds = %26
%30 = load i32, i32* %3
%31 = load i8*, i8** %4
%32 = load i32, i32* %6
%33 = call i32 (i32, ...) @write(i32 %30, i8* %31, i32 %32)
store i32 %33, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @fatalError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = load i32, i32* %3
%39 = call i32 @read(i32 %38, i32* %5, i32 4)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = icmp ne i32 %40, 4
br i1 %41, label %45, label %42
42: ; preds = %37
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42, %37
%46 = call i32 @fatalError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
br label %48
48: ; preds = %47, %26
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Response sending error 1\00"
@.str.1 = [25 x i8] c"Response sending error 2\00"
@.str.2 = [25 x i8] c"Response sending error 3\00"
@.str.3 = [25 x i8] c"Response sending error 4\00"
define i32 @sendResponseToClient(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, 1
store i32 %8, i32* %4
%9 = call i32 (i32, ...) @write(i32 %0, i32* %4, i32 4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @fatalError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = call i32 @read(i32 %0, i32* %3, i32 4)
%15 = icmp ne i32 %14, 4
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 0
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @fatalError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %13, %19
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 1
br i1 %23, label %37, label %24
24: ; preds = %21
%25 = call i32 (i32, ...) @write(i32 %0, i8* %1, i32 %22)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @fatalError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
%30 = call i32 @read(i32 %0, i32* %3, i32 4)
%31 = icmp ne i32 %30, 4
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 0
%34 = select i1 %31, i1 true, i1 %33
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @fatalError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %29, %21
ret i32 0
}