#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*/ close(int);
int /*<<< orphan*/ send_all(int, char *);
int strncmp(char *, char *, int);
void echo(int client, char *buf) {
  char *char_quit = "quit";
  int quit = strncmp(buf, char_quit, 4);
  if (quit == 0) {
    buf = "quit!";
  }
  send_all(client, buf);
  if (quit == 0) {
    close(client);
  }
}


x86 assembly (clang, -O0):
<echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1174 <echo+0x44>
lea    0xe95(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <send_all@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1192 <echo+0x62>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %eax,%ebp
test   %eax,%eax
lea    0xeac(%rip),%rsi
cmovne %rbx,%rsi
mov    %r14d,%edi
call   1050 <send_all@plt>
test   %ebp,%ebp
je     116e <echo+0x3e>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <close@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"quit\00"
@.str.1 = [6 x i8] c"quit!\00"
define void @echo(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %5
%7 = load i8*, i8** %4
%8 = load i8*, i8** %5
%9 = call i32 @strncmp(i8* %7, i8* %8, i32 4)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %13
13: ; preds = %12, %2
%14 = load i32, i32* %3
%15 = load i8*, i8** %4
%16 = call i32 @send_all(i32 %14, i8* %15)
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
br label %22
22: ; preds = %19, %13
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"quit\00"
@.str.1 = [6 x i8] c"quit!\00"
define void @echo(i32 %0, i8* %1) {
%3 = tail call i32 @strncmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1
%6 = tail call i32 @send_all(i32 %0, i8* %5)
br i1 %4, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @close(i32 %0)
br label %9
9: ; preds = %7, %2
ret void
}