#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 */
struct hitArgs {
  int dummy;
};

/* Variables and functions */
void send_api_response(struct hitArgs *, char *, char *);
void send_file_response(struct hitArgs *, char *, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
void send_response(struct hitArgs *args, char *path, char *request_body,
                   int type) {
  int path_length = (int)strlen(path);
  if (!strncmp(&path[path_length - 3], "api", 3)) {
    return send_api_response(args, path, request_body);
  }
  if (path_length == 0) {
    return send_file_response(args, "index.html", request_body, 10);
  }
  send_file_response(args, path, request_body, path_length);
}


x86 assembly (clang, -O0):
<send_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%eax
sub    $0x3,%eax
cltq
add    %rax,%rdi
lea    0xe87(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11a2 <send_response+0x62>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <send_api_response@plt>
jmp    11de <send_response+0x9e>
cmpl   $0x0,-0x20(%rbp)
jne    11ca <send_response+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe49(%rip),%rsi
mov    $0xa,%ecx
call   1060 <send_file_response@plt>
jmp    11de <send_response+0x9e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
call   1060 <send_file_response@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_response>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
add    $0xfffffffd,%eax
movslq %eax,%rdi
add    %rbx,%rdi
lea    0xe94(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     118d <send_response+0x4d>
test   %r12d,%r12d
je     11a6 <send_response+0x66>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r12d,%ecx
jmp    11b8 <send_response+0x78>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <send_api_response@plt>
lea    0xe57(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
mov    $0xa,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <send_file_response@plt>

LLVM IR (-O0):
%struct.hitArgs = type { i32 }
@.str = [4 x i8] c"api\00"
@.str.1 = [11 x i8] c"index.html\00"
define void @send_response(%struct.hitArgs* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca %struct.hitArgs*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store %struct.hitArgs* %0, %struct.hitArgs** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %6
%11 = call i64 @strlen(i8* %10)
%12 = trunc i64 %11 to i32
store i32 %12, i32* %9
%13 = load i8*, i8** %6
%14 = load i32, i32* %9
%15 = sub nsw i32 %14, 3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = call i32 @strncmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%19 = icmp ne i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %4
%21 = load %struct.hitArgs*, %struct.hitArgs** %5
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
br label %35
24: ; preds = %4
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load %struct.hitArgs*, %struct.hitArgs** %5
%29 = load i8*, i8** %7
br label %35
30: ; preds = %24
%31 = load %struct.hitArgs*, %struct.hitArgs** %5
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = load i32, i32* %9
br label %35
35: ; preds = %30, %27, %20
ret void
}

LLVM IR (-O2):
%struct.hitArgs = type { i32 }
@.str = [4 x i8] c"api\00"
@.str.1 = [11 x i8] c"index.html\00"
define void @send_response(%struct.hitArgs* %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = trunc i64 %5 to i32
%7 = shl i64 %5, 32
%8 = add i64 %7, -12884901888
%9 = ashr exact i64 %8, 32
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = tail call i32 @strncmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %4
tail call void @send_api_response(%struct.hitArgs* %0, i8* %1, i8* %2)
br label %18
14: ; preds = %4
%15 = icmp eq i32 %6, 0
br i1 %15, label %16, label %17
16: ; preds = %14
tail call void @send_file_response(%struct.hitArgs* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 10)
br label %18
17: ; preds = %14
tail call void @send_file_response(%struct.hitArgs* %0, i8* %1, i8* %2, i32 %6)
br label %18
18: ; preds = %17, %16, %13
ret void
}