#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*/ sprintf(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int handlemsg(char *msg, int len) {
  if (strncmp("ZERO", msg, 4) == 0)
    return 0;
  if (strncmp("BYE", msg, 3)) {
    sprintf(msg, "200 OK\r\n");
    return 8;
  }
  return -1;
}


x86 assembly (clang, -O0):
<handlemsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec6(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    115a <handlemsg+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    119c <handlemsg+0x7c>
mov    -0x10(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1195 <handlemsg+0x75>
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1040 <sprintf@plt>
movl   $0x8,-0x4(%rbp)
jmp    119c <handlemsg+0x7c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handlemsg>:
push   %rbx
mov    %rdi,%rbx
lea    0xee5(%rip),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     115e <handlemsg+0x4e>
lea    0xed1(%rip),%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1162 <handlemsg+0x52>
movabs $0xa0d4b4f20303032,%rax
4b 0d 0a
mov    %rax,(%rbx)
movb   $0x0,0x8(%rbx)
mov    $0x8,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"ZERO\00"
@.str.1 = [4 x i8] c"BYE\00"
@.str.2 = [9 x i8] c"200 OK\0D\0A\00"
define i32 @handlemsg(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %6, i32 4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %3
br label %18
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i64 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 3)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 8, i32* %3
br label %18
17: ; preds = %10
store i32 -1, i32* %3
br label %18
18: ; preds = %17, %14, %9
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [5 x i8] c"ZERO\00"
@.str.1 = [4 x i8] c"BYE\00"
@.str.2 = [9 x i8] c"200 OK\0D\0A\00"
define i32 @handlemsg(i8* %0, i32 %1) {
%3 = tail call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i32 4)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i64 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %5
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(9) %0, i8* align 1 dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64 9, i1 false)
br label %9
9: ; preds = %5, %2, %8
%10 = phi i32 [ 8, %8 ], [ 0, %2 ], [ -1, %5 ]
ret i32 %10
}