#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*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strlen(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int system(char *);
int sysexec(char *cmd, char *opt) {
  char buf[1024];
  int ret;
  if ((strlen(cmd) <= 0)) {
    syslog(LOG_INFO, "Trying to run empty command");
    return 0;
  }
  if (opt)
    sprintf(buf, "%s %s>/dev/null 2>&1", cmd, opt);
  else
    sprintf(buf, "%s >/dev/null 2>&1", cmd);
  syslog(LOG_INFO, "Running, system('%s')", buf);
  ret = system(buf);
  if (ret)
    syslog(LOG_ERR, "Error, %d from system('%s')", ret, buf);
  return ret;
}


x86 assembly (clang, -O0):
<sysexec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jg     1189 <sysexec+0x49>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1050 <syslog@plt>
movl   $0x0,-0x4(%rbp)
jmp    1239 <sysexec+0xf9>
cmpq   $0x0,-0x18(%rbp)
je     11b6 <sysexec+0x76>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    11cf <sysexec+0x8f>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1050 <syslog@plt>
lea    -0x420(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
je     1230 <sysexec+0xf0>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    -0x424(%rbp),%edx
lea    -0x420(%rbp),%rcx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1050 <syslog@plt>
mov    -0x424(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysexec>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
jle    1179 <sysexec+0x39>
test   %r14,%r14
je     1194 <sysexec+0x54>
lea    0xeb5(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <sprintf@plt>
jmp    11a8 <sysexec+0x68>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <syslog@plt>
jmp    11f3 <sysexec+0xb3>
lea    0xe96(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
xor    %ebx,%ebx
mov    %rsp,%rbp
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <syslog@plt>
mov    %rbp,%rdi
call   1040 <system@plt>
test   %eax,%eax
je     11f3 <sysexec+0xb3>
mov    %eax,%ebp
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
mov    %rsp,%rcx
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <syslog@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@LOG_INFO = global i32 0
@.str = [28 x i8] c"Trying to run empty command\00"
@.str.1 = [21 x i8] c"%s %s>/dev/null 2>&1\00"
@.str.2 = [19 x i8] c"%s >/dev/null 2>&1\00"
@.str.3 = [22 x i8] c"Running, system('%s')\00"
@LOG_ERR = global i32 0
@.str.4 = [28 x i8] c"Error, %d from system('%s')\00"
define i32 @sysexec(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = icmp sle i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @LOG_INFO
%13 = call i32 (i32, i8*, ...) @syslog(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %41
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20)
br label %26
22: ; preds = %14
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %22, %17
%27 = load i32, i32* @LOG_INFO
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = call i32 (i32, i8*, ...) @syslog(i32 %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%31 = call i32 @system(i8* %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %26
%35 = load i32, i32* @LOG_ERR
%36 = load i32, i32* %7
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%38 = call i32 (i32, i8*, ...) @syslog(i32 %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %36, i8* %37)
br label %39
39: ; preds = %34, %26
%40 = load i32, i32* %7
store i32 %40, i32* %3
br label %41
41: ; preds = %39, %11
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@LOG_INFO = global i32 0
@.str = [28 x i8] c"Trying to run empty command\00"
@.str.1 = [21 x i8] c"%s %s>/dev/null 2>&1\00"
@.str.2 = [19 x i8] c"%s >/dev/null 2>&1\00"
@.str.3 = [22 x i8] c"Running, system('%s')\00"
@LOG_ERR = global i32 0
@.str.4 = [28 x i8] c"Error, %d from system('%s')\00"
define i32 @sysexec(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = icmp slt i64 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @LOG_INFO
%9 = tail call i32 (i32, i8*, ...) @syslog(i32 %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %24
10: ; preds = %2
%11 = icmp eq i8* %1, null
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %16
14: ; preds = %10
%15 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %14, %12
%17 = load i32, i32* @LOG_INFO
%18 = call i32 (i32, i8*, ...) @syslog(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%19 = call i32 @system(i8* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32, i32* @LOG_ERR
%23 = call i32 (i32, i8*, ...) @syslog(i32 %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %19, i8* %4)
br label %24
24: ; preds = %16, %21, %7
%25 = phi i32 [ 0, %7 ], [ %19, %21 ], [ 0, %16 ]
ret i32 %25
}