#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*/ sprintf(char *, char *, char *, ...);
char *strcasestr(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void set_mobile_log(char *src, char *msg, char *time) {
  char prefix[1024], buffer[1024];
  char *ptr;
  if (time == NULL) {
    sprintf(src, "%s\n", msg);
    return;
  }
  strcpy(prefix, msg);
  strcpy(buffer, msg);
  ptr = strcasestr(prefix, "VID");
  if (ptr)
    *ptr = '\0';
  ptr = strcasestr(buffer, "VID");
  if (!ptr)
    sprintf(src, "%s\n", msg);
  else
    sprintf(src, "%s %s, %s\n", prefix, time, ptr);
}


x86 assembly (clang, -O0):
<set_mobile_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116d <set_mobile_log+0x3d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeaa(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1226 <set_mobile_log+0xf6>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1040 <strcasestr@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
je     11bf <set_mobile_log+0x8f>
mov    -0x828(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x820(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1040 <strcasestr@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
jne    1202 <set_mobile_log+0xd2>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1226 <set_mobile_log+0xf6>
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x828(%rbp),%r8
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_mobile_log>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdx,%rdx
je     11b6 <set_mobile_log+0x86>
mov    %rdx,%r15
lea    0x400(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe8f(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcasestr@plt>
test   %rax,%rax
je     1181 <set_mobile_log+0x51>
movb   $0x0,(%rax)
lea    0xe78(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcasestr@plt>
test   %rax,%rax
je     11d8 <set_mobile_log+0xa8>
lea    0xe68(%rip),%rsi
lea    0x400(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11ec <set_mobile_log+0xbc>
lea    0xe4e(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <sprintf@plt>
lea    0xe2c(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [4 x i8] c"VID\00"
@.str.2 = [11 x i8] c"%s %s, %s\0A\00"
define void @set_mobile_log(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %44
16: ; preds = %3
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%18 = load i8*, i8** %5
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%21 = load i8*, i8** %5
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = call i8* @strcasestr(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %16
%28 = load i8*, i8** %9
store i8 0, i8* %28
br label %29
29: ; preds = %27, %16
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%31 = call i8* @strcasestr(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %31, i8** %9
%32 = load i8*, i8** %9
%33 = icmp ne i8* %32, null
br i1 %33, label %38, label %34
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = load i8*, i8** %5
%37 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %36)
br label %44
38: ; preds = %29
%39 = load i8*, i8** %4
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%41 = load i8*, i8** %6
%42 = load i8*, i8** %9
%43 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %40, i8* %41, i8* %42)
br label %44
44: ; preds = %12, %38, %34
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [4 x i8] c"VID\00"
@.str.2 = [11 x i8] c"%s %s, %s\0A\00"
define void @set_mobile_log(i8* nocapture writeonly %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %2, null
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %24
11: ; preds = %3
%12 = call i32 @strcpy(i8* %6, i8* %1)
%13 = call i32 @strcpy(i8* %7, i8* %1)
%14 = call i8* @strcasestr(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %11
store i8 0, i8* %14
br label %17
17: ; preds = %16, %11
%18 = call i8* @strcasestr(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %24
22: ; preds = %17
%23 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %6, i8* %2, i8* %18)
br label %24
24: ; preds = %20, %22, %9
ret void
}