#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*/ LOG_INFO;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int WTERMSIG(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, ...);
int execute(char *msg, char *cmd) {
  int ret;
  FILE *f;
  char line[256];
  syslog(LOG_INFO, "executing: '%s'", cmd);
  strcat(cmd, " 2>&1");
  f = popen(cmd, "r");
  while (fgets(line, 255, f)) {
    line[strlen(line) - 1] = '\0';
    syslog(LOG_INFO, "+ %s", line);
  }
  ret = pclose(f);
  if (WIFEXITED(ret)) {
    if (WEXITSTATUS(ret))
      syslog(LOG_INFO, "%s exited with status %d", msg, WEXITSTATUS(ret));
    return WEXITSTATUS(ret);
  } else
    syslog(LOG_INFO, "%s exited on signal %d", msg, WTERMSIG(ret));
  return -1;
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
mov    -0x18(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x28(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0xff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     123d <execute+0xad>
lea    -0x130(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x130(%rbp,%rax,1)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rdx
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
jmp    11e2 <execute+0x52>
mov    -0x28(%rbp),%rdi
call   1040 <pclose@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   10b0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12bb <execute+0x12b>
mov    -0x1c(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     12ab <execute+0x11b>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x13c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rdx
mov    %eax,%ecx
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
mov    -0x1c(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    1301 <execute+0x171>
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    -0x14c(%rbp),%edi
mov    -0x148(%rbp),%rdx
mov    %eax,%ecx
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e34(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <syslog@plt>
lea    0xe49(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
lea    0xe40(%rip),%rsi
mov    %rbx,%rdi
call   1090 <popen@plt>
mov    %rax,%r15
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1234 <execute+0xa4>
lea    0xe18(%rip),%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    0x0(%rbp),%edi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <syslog@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1200 <execute+0x70>
mov    %r15,%rdi
call   1040 <pclose@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   10b0 <WIFEXITED@plt>
test   %rax,%rax
je     127d <execute+0xed>
mov    %ebx,%edi
call   1080 <WEXITSTATUS@plt>
test   %eax,%eax
je     1274 <execute+0xe4>
mov    0x0(%rbp),%ebp
mov    %ebx,%edi
call   1080 <WEXITSTATUS@plt>
lea    0xdb7(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <syslog@plt>
mov    %ebx,%edi
call   1080 <WEXITSTATUS@plt>
jmp    12a1 <execute+0x111>
mov    0x0(%rbp),%ebp
mov    %ebx,%edi
call   1060 <WTERMSIG@plt>
lea    0xda8(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LOG_INFO = global i32 0
@.str = [16 x i8] c"executing: '%s'\00"
@.str.1 = [6 x i8] c" 2>&1\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"+ %s\00"
@.str.4 = [25 x i8] c"%s exited with status %d\00"
@.str.5 = [23 x i8] c"%s exited on signal %d\00"
define i32 @execute(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [256 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i32, i32* @LOG_INFO
%10 = load i8*, i8** %5
%11 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %5
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8*, i8** %5
%15 = call i32* @popen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %15, i32** %7
br label %16
16: ; preds = %21, %2
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%18 = load i32*, i32** %7
%19 = call i64 @fgets(i8* %17, i32 255, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %25
store i8 0, i8* %26
%27 = load i32, i32* @LOG_INFO
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%29 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %16
30: ; preds = %16
%31 = load i32*, i32** %7
%32 = call i32 @pclose(i32* %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = call i64 @WIFEXITED(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %49
36: ; preds = %30
%37 = load i32, i32* %6
%38 = call i32 @WEXITSTATUS(i32 %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = load i32, i32* @LOG_INFO
%42 = load i8*, i8** %4
%43 = load i32, i32* %6
%44 = call i32 @WEXITSTATUS(i32 %43)
%45 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %41, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %42, i32 %44)
br label %46
46: ; preds = %40, %36
%47 = load i32, i32* %6
%48 = call i32 @WEXITSTATUS(i32 %47)
store i32 %48, i32* %3
br label %56
49: ; preds = %30
%50 = load i32, i32* @LOG_INFO
%51 = load i8*, i8** %4
%52 = load i32, i32* %6
%53 = call i32 @WTERMSIG(i32 %52)
%54 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %50, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %51, i32 %53)
br label %55
55: ; preds = %49
store i32 -1, i32* %3
br label %56
56: ; preds = %55, %46
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@LOG_INFO = global i32 0
@.str = [16 x i8] c"executing: '%s'\00"
@.str.1 = [6 x i8] c" 2>&1\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"+ %s\00"
@.str.4 = [25 x i8] c"%s exited with status %d\00"
@.str.5 = [23 x i8] c"%s exited on signal %d\00"
define i32 @execute(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @LOG_INFO
%6 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32* @popen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = call i64 @fgets(i8* %4, i32 255, i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %2, %11
%12 = call i32 @strlen(i8* %4)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %14
store i8 0, i8* %15
%16 = load i32, i32* @LOG_INFO
%17 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%18 = call i64 @fgets(i8* %4, i32 255, i32* %8)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %11
20: ; preds = %11, %2
%21 = call i32 @pclose(i32* %8)
%22 = call i64 @WIFEXITED(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %20
%25 = call i32 @WEXITSTATUS(i32 %21)
%26 = icmp eq i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = load i32, i32* @LOG_INFO
%29 = call i32 @WEXITSTATUS(i32 %21)
%30 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %29)
br label %31
31: ; preds = %27, %24
%32 = call i32 @WEXITSTATUS(i32 %21)
br label %37
33: ; preds = %20
%34 = load i32, i32* @LOG_INFO
%35 = call i32 @WTERMSIG(i32 %21)
%36 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %0, i32 %35)
br label %37
37: ; preds = %33, %31
%38 = phi i32 [ %32, %31 ], [ -1, %33 ]
ret i32 %38
}