#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strcspn(char *, char *);
int strlen(char *);
void log_wrapper(FILE *logf, char *msg, char *filename) {
  char log_buf[255];
  strcpy(log_buf, msg);
  snprintf(log_buf + strlen(log_buf), 255 - strlen(log_buf) - 1, filename);
  log_buf[strcspn(log_buf, "\n")] = '\0';
  fprintf(logf, "LOG: %s\n", log_buf);
}


x86 assembly (clang, -O0):
<log_wrapper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x130(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x128(%rbp),%rdi
mov    $0xff,%esi
sub    %eax,%esi
sub    $0x1,%esi
mov    -0x18(%rbp),%rdx
call   1050 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1060 <strcspn@plt>
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe06(%rip),%rsi
call   1070 <fprintf@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_wrapper>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r15
mov    %rdi,%r14
mov    %rsp,%r12
mov    %r12,%rdi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    $0xfe,%esi
sub    %eax,%esi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1050 <snprintf@plt>
lea    0xe69(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcspn@plt>
movb   $0x0,(%rsp,%rax,1)
lea    0xe4f(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
call   1070 <fprintf@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [9 x i8] c"LOG: %s\0A\00"
define void @log_wrapper(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [255 x i8]
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %5
%10 = call i32 @strcpy(i8* %8, i8* %9)
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 255, %17
%19 = sub nsw i32 %18, 1
%20 = load i8*, i8** %6
%21 = call i32 @snprintf(i8* %15, i32 %19, i8* %20)
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%23 = call i64 @strcspn(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 %23
store i8 0, i8* %24
%25 = load i32*, i32** %4
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%27 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %26)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [9 x i8] c"LOG: %s\0A\00"
define void @log_wrapper(i32* nocapture %0, i8* %1, i8* %2) {
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* %1)
%7 = call i32 @strlen(i8* %5)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 %8
%10 = call i32 @strlen(i8* %5)
%11 = sub i32 254, %10
%12 = call i32 @snprintf(i8* %9, i32 %11, i8* %2)
%13 = call i64 @strcspn(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %5)
ret void
}