#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*/ sendMsg(int, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void sendCustom(int sockfd, char type, char payload[]) {
  char fullPayload[9];
  if (type == 0x01) {
    fullPayload[0] = 0x01;
    strncpy(fullPayload + 1, payload, 8);
    sendMsg(sockfd, fullPayload, 9);
  } else if (type == 0x02) {
    fullPayload[0] = 0x02;
    strncpy(fullPayload + 1, payload, 6);
    sendMsg(sockfd, fullPayload, 7);
  }
}


x86 assembly (clang, -O0):
<sendCustom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %rdx,-0x10(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x1,%eax
jne    1172 <sendCustom+0x52>
movb   $0x1,-0x19(%rbp)
lea    -0x19(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x9,%edx
call   1040 <sendMsg@plt>
jmp    11af <sendCustom+0x8f>
movsbl -0x5(%rbp),%eax
cmp    $0x2,%eax
jne    11aa <sendCustom+0x8a>
movb   $0x2,-0x19(%rbp)
lea    -0x19(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x7,%edx
call   1040 <sendMsg@plt>
jmp    11af <sendCustom+0x8f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendCustom>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
cmp    $0x1,%sil
je     1140 <sendCustom+0x20>
cmp    $0x2,%sil
jne    116c <sendCustom+0x4c>
mov    $0x7,%ebp
mov    $0x6,%eax
jmp    114a <sendCustom+0x2a>
mov    $0x9,%ebp
mov    $0x8,%eax
mov    %sil,0xf(%rsp)
lea    0x10(%rsp),%rdi
mov    %rdx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   1040 <sendMsg@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @sendCustom(i32 %0, i8 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca [9 x i8]
store i32 %0, i32* %4
store i8 %1, i8* %5
store i8* %2, i8** %6
%8 = load i8, i8* %5
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %20
11: ; preds = %3
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
store i8 1, i8* %12
%13 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8*, i8** %6
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 8)
%17 = load i32, i32* %4
%18 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%19 = call i32 @sendMsg(i32 %17, i8* %18, i32 9)
br label %34
20: ; preds = %3
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
store i8 2, i8* %25
%26 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8*, i8** %6
%29 = call i32 @strncpy(i8* %27, i8* %28, i32 6)
%30 = load i32, i32* %4
%31 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%32 = call i32 @sendMsg(i32 %30, i8* %31, i32 7)
br label %33
33: ; preds = %24, %20
br label %34
34: ; preds = %33, %11
ret void
}

LLVM IR (-O2):
define void @sendCustom(i32 %0, i8 signext %1, i8* %2) {
%4 = alloca [9 x i8]
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
switch i8 %1, label %13 [
i8 1, label %7
i8 2, label %6
]
6: ; preds = %3
br label %7
7: ; preds = %3, %6
%8 = phi i32 [ 6, %6 ], [ 8, %3 ]
%9 = phi i32 [ 7, %6 ], [ 9, %3 ]
store i8 %1, i8* %5
%10 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 1
%11 = call i32 @strncpy(i8* %10, i8* %2, i32 %8)
%12 = call i32 @sendMsg(i32 %0, i8* %5, i32 %9)
br label %13
13: ; preds = %7, %3
ret void
}