#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void syslog_edit_comma(char *msg, int flag, int time_len) {
  char tmp_msg[128 + 1] = "";
  int tmp_len = 0;
  int max_log_len;
  max_log_len = 128 - time_len;
  strncpy(tmp_msg, msg, 128);
  tmp_len = strlen(tmp_msg) - 1;
  while ((tmp_len > 0) && (tmp_msg[tmp_len] == ' ')) {
    tmp_len--;
  }
  if (flag == 1) {
    if ((tmp_msg[tmp_len] != ',') && (tmp_msg[tmp_len] != ']')) {
      if ((tmp_len + 1) < max_log_len)
        tmp_msg[tmp_len + 1] = ',';
      else
        tmp_msg[tmp_len] = ',';
    }
  } else if (flag == 0) {
    if (tmp_msg[tmp_len] == ',')
      tmp_msg[tmp_len] = ' ';
  }
  strncpy(msg, tmp_msg, 128);
}


x86 assembly (clang, -O0):
<syslog_edit_comma>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x81,%edx
call   1050 <memset@plt>
movl   $0x0,-0xa4(%rbp)
mov    $0x80,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xa4(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xa4(%rbp)
mov    %al,-0xa9(%rbp)
jle    11ca <syslog_edit_comma+0x9a>
movslq -0xa4(%rbp),%rax
movsbl -0xa0(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
sete   %al
mov    %al,-0xa9(%rbp)
mov    -0xa9(%rbp),%al
test   $0x1,%al
jne    11dd <syslog_edit_comma+0xad>
jmp    11f1 <syslog_edit_comma+0xc1>
mov    -0xa4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xa4(%rbp)
jmp    119a <syslog_edit_comma+0x6a>
cmpl   $0x1,-0xc(%rbp)
jne    1271 <syslog_edit_comma+0x141>
movslq -0xa4(%rbp),%rax
movsbl -0xa0(%rbp,%rax,1),%eax
ff
cmp    $0x2c,%eax
je     126c <syslog_edit_comma+0x13c>
movslq -0xa4(%rbp),%rax
movsbl -0xa0(%rbp,%rax,1),%eax
ff
cmp    $0x5d,%eax
je     126c <syslog_edit_comma+0x13c>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
cmp    -0xa8(%rbp),%eax
jge    1258 <syslog_edit_comma+0x128>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x2c,-0xa0(%rbp,%rax,1)
2c
jmp    1267 <syslog_edit_comma+0x137>
movslq -0xa4(%rbp),%rax
movb   $0x2c,-0xa0(%rbp,%rax,1)
2c
jmp    126c <syslog_edit_comma+0x13c>
jmp    12ac <syslog_edit_comma+0x17c>
cmpl   $0x0,-0xc(%rbp)
jne    12a7 <syslog_edit_comma+0x177>
movslq -0xa4(%rbp),%rax
movsbl -0xa0(%rbp,%rax,1),%eax
ff
cmp    $0x2c,%eax
jne    12a2 <syslog_edit_comma+0x172>
movslq -0xa4(%rbp),%rax
movb   $0x20,-0xa0(%rbp,%rax,1)
20
jmp    12a7 <syslog_edit_comma+0x177>
jmp    12ac <syslog_edit_comma+0x17c>
mov    -0x8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<syslog_edit_comma>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movb   $0x0,0x80(%rsp)
mov    $0x80,%ebp
sub    %edx,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
test   %eax,%eax
mov    $0x1,%ecx
cmovle %eax,%ecx
lea    -0x1(%rcx),%eax
cs nopw 0x0(%rax,%rax,1)
cmp    $0x2,%edx
jl     11b6 <syslog_edit_comma+0x96>
add    $0xffffffffffffffff,%rdx
mov    %edx,%esi
cmpb   $0x20,(%rsp,%rsi,1)
je     11a0 <syslog_edit_comma+0x80>
lea    0x1(%rdx),%ecx
mov    %edx,%eax
test   %r15d,%r15d
je     11dd <syslog_edit_comma+0xbd>
cmp    $0x1,%r15d
jne    11e9 <syslog_edit_comma+0xc9>
cltq
mov    (%rsp,%rax,1),%dl
cmp    $0x2c,%dl
je     11e9 <syslog_edit_comma+0xc9>
cmp    $0x5d,%dl
je     11e9 <syslog_edit_comma+0xc9>
cmp    %ebp,%ecx
jge    11d7 <syslog_edit_comma+0xb7>
movslq %ecx,%rax
movb   $0x2c,(%rsp,%rax,1)
jmp    11e9 <syslog_edit_comma+0xc9>
cltq
cmpb   $0x2c,(%rsp,%rax,1)
jne    11e9 <syslog_edit_comma+0xc9>
movb   $0x20,(%rsp,%rax,1)
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x80,%edx
call   1030 <strncpy@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @syslog_edit_comma(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [129 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = bitcast [129 x i8]* %7 to i8*
store i32 0, i32* %8
%11 = load i32, i32* %6
%12 = sub nsw i32 128, %11
store i32 %12, i32* %9
%13 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 0
%14 = load i8*, i8** %4
%15 = call i32 @strncpy(i8* %13, i8* %14, i32 128)
%16 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %17, 1
store i32 %18, i32* %8
br label %19
19: ; preds = %31, %3
%20 = load i32, i32* %8
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 32
br label %29
29: ; preds = %22, %19
%30 = phi i1 [ false, %19 ], [ %28, %22 ]
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = load i32, i32* %8
%33 = add nsw i32 %32, -1
store i32 %33, i32* %8
br label %19
34: ; preds = %29
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %67
37: ; preds = %34
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 44
br i1 %43, label %44, label %66
44: ; preds = %37
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 93
br i1 %50, label %51, label %66
51: ; preds = %44
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
%54 = load i32, i32* %9
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %61
56: ; preds = %51
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 %59
store i8 44, i8* %60
br label %65
61: ; preds = %51
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 %63
store i8 44, i8* %64
br label %65
65: ; preds = %61, %56
br label %66
66: ; preds = %65, %44, %37
br label %83
67: ; preds = %34
%68 = load i32, i32* %5
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %82
70: ; preds = %67
%71 = load i32, i32* %8
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 %72
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 44
br i1 %76, label %77, label %81
77: ; preds = %70
%78 = load i32, i32* %8
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 %79
store i8 32, i8* %80
br label %81
81: ; preds = %77, %70
br label %82
82: ; preds = %81, %67
br label %83
83: ; preds = %82, %66
%84 = load i8*, i8** %4
%85 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 0
%86 = call i32 @strncpy(i8* %84, i8* %85, i32 128)
ret void
}

LLVM IR (-O2):
define void @syslog_edit_comma(i8* %0, i32 %1, i32 %2) {
%4 = alloca [129 x i8]
%5 = getelementptr inbounds [129 x i8], [129 x i8]* %4, i64 0, i64 0
%6 = sub nsw i32 128, %2
%7 = call i32 @strncpy(i8* %5, i8* %0, i32 128)
%8 = call i32 @strlen(i8* %5)
%9 = zext i32 %8 to i64
%10 = call i32 @llvm.smin.i32(i32 %8, i32 1)
%11 = add i32 %10, -1
br label %12
12: ; preds = %17, %3
%13 = phi i64 [ %14, %17 ], [ %9, %3 ]
%14 = add nsw i64 %13, -1
%15 = trunc i64 %13 to i32
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = and i64 %14, 4294967295
%19 = getelementptr inbounds [129 x i8], [129 x i8]* %4, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 32
br i1 %21, label %12, label %22
22: ; preds = %17
%23 = trunc i64 %13 to i32
%24 = trunc i64 %14 to i32
br label %25
25: ; preds = %12, %22
%26 = phi i32 [ %23, %22 ], [ %10, %12 ]
%27 = phi i32 [ %24, %22 ], [ %11, %12 ]
switch i32 %1, label %44 [
i32 1, label %28
i32 0, label %38
]
28: ; preds = %25
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds [129 x i8], [129 x i8]* %4, i64 0, i64 %29
%31 = load i8, i8* %30
switch i8 %31, label %32 [
i8 44, label %44
i8 93, label %44
]
32: ; preds = %28
%33 = icmp slt i32 %26, %6
br i1 %33, label %34, label %37
34: ; preds = %32
%35 = sext i32 %26 to i64
%36 = getelementptr inbounds [129 x i8], [129 x i8]* %4, i64 0, i64 %35
store i8 44, i8* %36
br label %44
37: ; preds = %32
store i8 44, i8* %30
br label %44
38: ; preds = %25
%39 = sext i32 %27 to i64
%40 = getelementptr inbounds [129 x i8], [129 x i8]* %4, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 44
br i1 %42, label %43, label %44
43: ; preds = %38
store i8 32, i8* %40
br label %44
44: ; preds = %25, %28, %28, %43, %38, %37, %34
%45 = call i32 @strncpy(i8* %0, i8* %5, i32 128)
ret void
}