void logToSomeFile(char buffer[200], int fileChoice) {
  char ToLog[] = ">> log";
  char ToDebug[] = ">> debug";
  char ToError[] = ">> error";
  char ToOpenPorts[] = ">> availablePorts";
  char newbuff[250];
  memset(newbuff, 0, 250);
  strcat(newbuff, buffer);
  printf("First strcat: %s", &newbuff);
  if (fileChoice == 1) {
    strcat(newbuff, ToLog);
  } else if (fileChoice == 2) {
    strcat(newbuff, ToDebug);
  } else if (fileChoice == 3) {
    strcat(newbuff, ToError);
  } else if (fileChoice == 4) {
    strcat(newbuff, ToOpenPorts);
  }
  printf("Before system: %s", &newbuff);
  int ignoringThis = system(newbuff);
}


x86 assembly (clang, -O0):
<logToSomeFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xea8(%rip),%eax
mov    %eax,-0x13(%rbp)
mov    0xea2(%rip),%ax
mov    %ax,-0xf(%rbp)
mov    0xe9a(%rip),%al
mov    %al,-0xd(%rbp)
mov    0xe91(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xe8f(%rip),%al
mov    %al,-0x14(%rbp)
mov    0xe86(%rip),%rax
mov    %rax,-0x25(%rbp)
mov    0xe84(%rip),%al
mov    %al,-0x1d(%rbp)
mov    0xea2(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe9f(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe9c(%rip),%ax
mov    %ax,-0x30(%rbp)
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1050 <memset@plt>
lea    -0x140(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
lea    0xe37(%rip),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0xc(%rbp)
jne    120f <logToSomeFile+0xcf>
lea    -0x140(%rbp),%rdi
lea    -0x13(%rbp),%rsi
call   1060 <strcat@plt>
jmp    1276 <logToSomeFile+0x136>
cmpl   $0x2,-0xc(%rbp)
jne    122e <logToSomeFile+0xee>
lea    -0x140(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1060 <strcat@plt>
jmp    1271 <logToSomeFile+0x131>
cmpl   $0x3,-0xc(%rbp)
jne    124d <logToSomeFile+0x10d>
lea    -0x140(%rbp),%rdi
lea    -0x25(%rbp),%rsi
call   1060 <strcat@plt>
jmp    126c <logToSomeFile+0x12c>
cmpl   $0x4,-0xc(%rbp)
jne    1267 <logToSomeFile+0x127>
lea    -0x140(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <strcat@plt>
jmp    126c <logToSomeFile+0x12c>
jmp    1271 <logToSomeFile+0x131>
jmp    1276 <logToSomeFile+0x136>
lea    0xdad(%rip),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x140(%rbp),%rdi
mov    $0x0,%al
call   1030 <system@plt>
mov    %eax,-0x144(%rbp)
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logToSomeFile>:
push   %r14
push   %rbx
sub    $0x158,%rsp
mov    %esi,%ebx
mov    %rdi,%rsi
movl   $0x676f6c,0xb(%rsp)
movl   $0x6c203e3e,0x8(%rsp)
6c
movabs $0x6775626564203e3e,%rax
62 75 67
mov    %rax,0x20(%rsp)
movb   $0x0,0x28(%rsp)
movabs $0x726f727265203e3e,%rax
72 6f 72
mov    %rax,0x10(%rsp)
movb   $0x0,0x18(%rsp)
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movw   $0x73,0x40(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x13a(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
lea    0x50(%rsp),%r14
mov    %r14,%rdi
call   1050 <strcat@plt>
lea    0xe11(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebx
cmp    $0x3,%ebx
ja     125c <logToSomeFile+0x12c>
lea    0x8(%rsp),%rsi
lea    0xdca(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    0x20(%rsp),%rsi
jmp    1252 <logToSomeFile+0x122>
lea    0x10(%rsp),%rsi
jmp    1252 <logToSomeFile+0x122>
lea    0x30(%rsp),%rsi
lea    0x50(%rsp),%rdi
call   1050 <strcat@plt>
lea    0xdd7(%rip),%rdi
lea    0x50(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <system@plt>
add    $0x158,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.logToSomeFile.ToLog = [7 x i8] c">> log\00"
@__const.logToSomeFile.ToDebug = [9 x i8] c">> debug\00"
@__const.logToSomeFile.ToError = [9 x i8] c">> error\00"
@__const.logToSomeFile.ToOpenPorts = [18 x i8] c">> availablePorts\00"
@.str = [17 x i8] c"First strcat: %s\00"
@.str.1 = [18 x i8] c"Before system: %s\00"
define void @logToSomeFile(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [7 x i8]
%6 = alloca [9 x i8]
%7 = alloca [9 x i8]
%8 = alloca [18 x i8]
%9 = alloca [250 x i8]
%10 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = bitcast [7 x i8]* %5 to i8*
%12 = bitcast [9 x i8]* %6 to i8*
%13 = bitcast [9 x i8]* %7 to i8*
%14 = bitcast [18 x i8]* %8 to i8*
%15 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%16 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%17 = load i8*, i8** %3
%18 = call i8* @strcat(i8* %16, i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), [250 x i8]* %9)
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%24 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%25 = call i8* @strcat(i8* %23, i8* %24)
br label %50
26: ; preds = %2
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%31 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%32 = call i8* @strcat(i8* %30, i8* %31)
br label %49
33: ; preds = %26
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 3
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%38 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%39 = call i8* @strcat(i8* %37, i8* %38)
br label %48
40: ; preds = %33
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 4
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%45 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
%46 = call i8* @strcat(i8* %44, i8* %45)
br label %47
47: ; preds = %43, %40
br label %48
48: ; preds = %47, %36
br label %49
49: ; preds = %48, %29
br label %50
50: ; preds = %49, %22
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), [250 x i8]* %9)
%52 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%53 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %52)
store i32 %53, i32* %10
ret void
}

LLVM IR (-O2):
@__const.logToSomeFile.ToLog = [7 x i8] c">> log\00"
@__const.logToSomeFile.ToDebug = [9 x i8] c">> debug\00"
@__const.logToSomeFile.ToError = [9 x i8] c">> error\00"
@__const.logToSomeFile.ToOpenPorts = [18 x i8] c">> availablePorts\00"
@.str = [17 x i8] c"First strcat: %s\00"
@.str.1 = [18 x i8] c"Before system: %s\00"
define void @logToSomeFile(i8* nocapture %0, i32 %1) {
%3 = alloca [7 x i8]
%4 = alloca [9 x i8]
%5 = alloca [9 x i8]
%6 = alloca [18 x i8]
%7 = alloca [250 x i8]
%8 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [250 x i8], [250 x i8]* %7, i64 0, i64 0
%13 = call i8* @strcat(i8* %12, i8* dereferenceable(1) %0)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), [250 x i8]* %7)
switch i32 %1, label %21 [
i32 1, label %18
i32 2, label %15
i32 3, label %16
i32 4, label %17
]
15: ; preds = %2
br label %18
16: ; preds = %2
br label %18
17: ; preds = %2
br label %18
18: ; preds = %2, %16, %17, %15
%19 = phi i8* [ %9, %15 ], [ %11, %17 ], [ %10, %16 ], [ %8, %2 ]
%20 = call i8* @strcat(i8* %12, i8* %19)
br label %21
21: ; preds = %18, %2
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), [250 x i8]* %7)
%23 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %12)
ret void
}