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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ debugMsg(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int execCmd(char *cmd) {
  debugMsg("execCmd() ...");
  char ret[10];
  FILE *fd = popen(cmd, "r");
  if (fd == NULL) {
    return -1;
  }
  while (fgets(ret, sizeof(ret) - 1, fd) != NULL)
    ;
  int ret_val = atoi(ret);
  debugMsg("execCmd() ... ok ...");
  return ret_val;
}


x86 assembly (clang, -O0):
<execCmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
call   1040 <debugMsg@plt>
mov    -0x10(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1183 <execCmd+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <execCmd+0x87>
jmp    1188 <execCmd+0x48>
lea    -0x1a(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x9,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11a9 <execCmd+0x69>
jmp    1188 <execCmd+0x48>
lea    -0x1a(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x2c(%rbp)
lea    0xe54(%rip),%rdi
call   1040 <debugMsg@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execCmd>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xeaf(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0xeb1(%rip),%rsi
mov    %rbx,%rdi
call   1050 <popen@plt>
test   %rax,%rax
je     11af <execCmd+0x6f>
mov    %rax,%rbx
lea    0xe(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x9,%esi
mov    %rbx,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
jne    1180 <execCmd+0x40>
lea    0xe(%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
lea    0xe68(%rip),%rdi
call   1040 <debugMsg@plt>
jmp    11b4 <execCmd+0x74>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"execCmd() ...\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"execCmd() ... ok ...\00"
define i32 @execCmd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [10 x i8]
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
%7 = call i32 @debugMsg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %3
%9 = call i32* @popen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %25
13: ; preds = %1
br label %14
14: ; preds = %19, %13
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i32* @fgets(i8* %15, i32 9, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %14
br label %14
20: ; preds = %14
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = call i32 @debugMsg(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* %6
store i32 %24, i32* %2
br label %25
25: ; preds = %20, %12
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [14 x i8] c"execCmd() ...\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"execCmd() ... ok ...\00"
define i32 @execCmd(i8* nocapture %0) {
%2 = alloca [10 x i8]
%3 = tail call i32 @debugMsg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %13, label %7
7: ; preds = %1, %7
%8 = call i32* @fgets(i8* %4, i32 9, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %7
10: ; preds = %7
%11 = call i32 @atoi(i8* %4)
%12 = call i32 @debugMsg(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %1, %10
%14 = phi i32 [ %11, %10 ], [ -1, %1 ]
ret i32 %14
}