#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 vcLog {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ disable_logging(struct vcLog *);
struct vcLog *init_cvector(char *, char *);
int /*<<< orphan*/ log_local_event(struct vcLog *, char *);
char *prepare_send(struct vcLog *, char *, char *, int, int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *unpack_receive(struct vcLog *, char *, char *, int, int *);
int main() {
  struct vcLog *vcInfo = init_cvector("MyProcess", "basiclog");
  int size;
  int msgLen;
  char sendingMessage[50];
  strcpy(sendingMessage, "ExampleMessage");
  printf("We are packing this message: %s\n", sendingMessage);
  char *resultBuffer =
      prepare_send(vcInfo, "Sending Message", sendingMessage, 50, &size);
  char *receivedMessage =
      unpack_receive(vcInfo, "Receiving Message", resultBuffer, size, &msgLen);
  printf("We received this message: %s\n", receivedMessage);
  log_local_event(vcInfo, "Example Complete");
  disable_logging(vcInfo);
  log_local_event(vcInfo, "This will not be logged.");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xe81(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1090 <init_cvector@plt>
mov    %rax,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1060 <strcpy@plt>
lea    -0x50(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1080 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe85(%rip),%rsi
mov    $0x32,%ecx
lea    -0xc(%rbp),%r8
call   1030 <prepare_send@plt>
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe71(%rip),%rsi
lea    -0x10(%rbp),%r8
call   1070 <unpack_receive@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1080 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1040 <log_local_event@plt>
mov    -0x8(%rbp),%rdi
call   1050 <disable_logging@plt>
mov    -0x8(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1040 <log_local_event@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xe82(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1090 <init_cvector@plt>
mov    %rax,%rbx
lea    0xe7f(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1060 <strcpy@plt>
lea    0xe7a(%rip),%rdi
mov    %r14,%rsi
call   1080 <printf@plt>
lea    0xe8c(%rip),%rsi
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x32,%ecx
call   1030 <prepare_send@plt>
mov    0x8(%rsp),%ecx
lea    0xe7c(%rip),%rsi
lea    0xc(%rsp),%r8
mov    %rbx,%rdi
mov    %rax,%rdx
call   1070 <unpack_receive@plt>
lea    0xe77(%rip),%rdi
mov    %rax,%rsi
call   1080 <printf@plt>
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
call   1040 <log_local_event@plt>
mov    %rbx,%rdi
call   1050 <disable_logging@plt>
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
call   1040 <log_local_event@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.vcLog = type { i32 }
@.str = [10 x i8] c"MyProcess\00"
@.str.1 = [9 x i8] c"basiclog\00"
@.str.2 = [15 x i8] c"ExampleMessage\00"
@.str.3 = [33 x i8] c"We are packing this message: %s\0A\00"
@.str.4 = [16 x i8] c"Sending Message\00"
@.str.5 = [18 x i8] c"Receiving Message\00"
@.str.6 = [30 x i8] c"We received this message: %s\0A\00"
@.str.7 = [17 x i8] c"Example Complete\00"
@.str.8 = [25 x i8] c"This will not be logged.\00"
define i32 @main() {
%1 = alloca %struct.vcLog*
%2 = alloca i32
%3 = alloca i32
%4 = alloca [50 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = call %struct.vcLog* @init_cvector(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store %struct.vcLog* %7, %struct.vcLog** %1
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%11 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = load %struct.vcLog*, %struct.vcLog** %1
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%14 = call i8* @prepare_send(%struct.vcLog* %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %13, i32 50, i32* %2)
store i8* %14, i8** %5
%15 = load %struct.vcLog*, %struct.vcLog** %1
%16 = load i8*, i8** %5
%17 = load i32, i32* %2
%18 = call i8* @unpack_receive(%struct.vcLog* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %16, i32 %17, i32* %3)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %19)
%21 = load %struct.vcLog*, %struct.vcLog** %1
%22 = call i32 @log_local_event(%struct.vcLog* %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%23 = load %struct.vcLog*, %struct.vcLog** %1
%24 = call i32 @disable_logging(%struct.vcLog* %23)
%25 = load %struct.vcLog*, %struct.vcLog** %1
%26 = call i32 @log_local_event(%struct.vcLog* %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.vcLog = type { i32 }
@.str = [10 x i8] c"MyProcess\00"
@.str.1 = [9 x i8] c"basiclog\00"
@.str.2 = [15 x i8] c"ExampleMessage\00"
@.str.3 = [33 x i8] c"We are packing this message: %s\0A\00"
@.str.4 = [16 x i8] c"Sending Message\00"
@.str.5 = [18 x i8] c"Receiving Message\00"
@.str.6 = [30 x i8] c"We received this message: %s\0A\00"
@.str.7 = [17 x i8] c"Example Complete\00"
@.str.8 = [25 x i8] c"This will not be logged.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [50 x i8]
%4 = tail call %struct.vcLog* @init_cvector(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%10 = call i8* @prepare_send(%struct.vcLog* %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %7, i32 50, i32* %1)
%11 = load i32, i32* %1
%12 = call i8* @unpack_receive(%struct.vcLog* %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %10, i32 %11, i32* %2)
%13 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%14 = call i32 @log_local_event(%struct.vcLog* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%15 = call i32 @disable_logging(%struct.vcLog* %4)
%16 = call i32 @log_local_event(%struct.vcLog* %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}