#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*/ buf;

/* Variables and functions */
int execute_ret(char *, int, char *);
int sscanf(char *, char *, int *, int *, int *);
int get_iptables_version() {
  char buf[256];
  int minor;
  int major;
  int patch;
  int rc;
  rc = execute_ret(buf, sizeof(buf), "iptables -V");
  if (rc == 0 &&
      sscanf(buf, "iptables v%d.%d.%d", &major, &minor, &patch) == 3) {
    return major * 10000 + minor * 100 + patch;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<get_iptables_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
lea    0xec2(%rip),%rdx
call   1030 <execute_ret@plt>
mov    %eax,-0x120(%rbp)
cmpl   $0x0,-0x120(%rbp)
jne    11a8 <get_iptables_version+0x88>
lea    -0x110(%rbp),%rdi
lea    0xea8(%rip),%rsi
lea    -0x118(%rbp),%rdx
lea    -0x114(%rbp),%rcx
lea    -0x11c(%rbp),%r8
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    11a8 <get_iptables_version+0x88>
imul   $0x2710,-0x118(%rbp),%eax
imul   $0x64,-0x114(%rbp),%ecx
add    %ecx,%eax
add    -0x11c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11af <get_iptables_version+0x8f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_iptables_version>:
push   %rbx
sub    $0x110,%rsp
lea    0xed1(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
call   1030 <execute_ret@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
jne    117f <get_iptables_version+0x5f>
lea    0xebe(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x4(%rsp),%r8
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    117f <get_iptables_version+0x5f>
imul   $0x2710,0x8(%rsp),%eax
imul   $0x64,0xc(%rsp),%ebx
add    %eax,%ebx
add    0x4(%rsp),%ebx
mov    %ebx,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"iptables -V\00"
@.str.1 = [19 x i8] c"iptables v%d.%d.%d\00"
define i32 @get_iptables_version() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%8 = call i32 @execute_ret(i8* %7, i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %3, i32* %5)
%14 = icmp eq i32 %13, 3
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i32, i32* %4
%17 = mul nsw i32 %16, 10000
%18 = load i32, i32* %3
%19 = mul nsw i32 %18, 100
%20 = add nsw i32 %17, %19
%21 = load i32, i32* %5
%22 = add nsw i32 %20, %21
store i32 %22, i32* %1
br label %24
23: ; preds = %11, %0
store i32 -1, i32* %1
br label %24
24: ; preds = %23, %15
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [12 x i8] c"iptables -V\00"
@.str.1 = [19 x i8] c"iptables v%d.%d.%d\00"
define i32 @get_iptables_version() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i32 @execute_ret(i8* %5, i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %0
%12 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %2, i32* %4)
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load i32, i32* %3
%16 = mul nsw i32 %15, 10000
%17 = load i32, i32* %2
%18 = mul nsw i32 %17, 100
%19 = add nsw i32 %18, %16
%20 = load i32, i32* %4
%21 = add nsw i32 %19, %20
br label %22
22: ; preds = %0, %11, %14
%23 = phi i32 [ %21, %14 ], [ -1, %11 ], [ -1, %0 ]
ret i32 %23
}