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

/* Variables and functions */
int /*<<< orphan*/ osSystem_GetOutput(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int utilGetlockByName(char *filename, int *fd, int type) {
  int ret = (0);
  char tmpBuf[255];
  char cmd[70];
  char fn[50];
  if (filename) {
    strncpy(fn, filename, 50);
  } else {
    strncpy(fn, "/var/lock/iptables.lock", 50);
  }
  if (type == 0) {
    sprintf(cmd, "lock %s", fn);
    osSystem_GetOutput(cmd, tmpBuf, sizeof(tmpBuf));
  } else {
    sprintf(cmd, "lock -u %s", fn);
    osSystem_GetOutput(cmd, tmpBuf, sizeof(tmpBuf));
  }
  return ret;
}


x86 assembly (clang, -O0):
<utilGetlockByName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1172 <utilGetlockByName+0x42>
lea    -0x1b0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
jmp    118a <utilGetlockByName+0x5a>
lea    -0x1b0(%rbp),%rdi
lea    0xe80(%rip),%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11cb <utilGetlockByName+0x9b>
lea    -0x170(%rbp),%rdi
lea    -0x1b0(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x170(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1040 <osSystem_GetOutput@plt>
jmp    11fd <utilGetlockByName+0xcd>
lea    -0x170(%rbp),%rdi
lea    -0x1b0(%rbp),%rdx
lea    0xe40(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x170(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1040 <osSystem_GetOutput@plt>
mov    -0x18(%rbp),%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utilGetlockByName>:
push   %rbx
sub    $0x190,%rsp
mov    %edx,%ebx
test   %rdi,%rdi
je     1144 <utilGetlockByName+0x14>
mov    %rdi,%rsi
jmp    114b <utilGetlockByName+0x1b>
lea    0xeb5(%rip),%rsi
mov    %rsp,%rdi
mov    $0x32,%edx
call   1030 <strncpy@plt>
test   %ebx,%ebx
lea    0xeb7(%rip),%rax
lea    0xeb8(%rip),%rsi
cmove  %rax,%rsi
lea    0x40(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
lea    0x90(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xff,%edx
call   1040 <osSystem_GetOutput@plt>
xor    %eax,%eax
add    $0x190,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/var/lock/iptables.lock\00"
@.str.1 = [8 x i8] c"lock %s\00"
@.str.2 = [11 x i8] c"lock -u %s\00"
define i32 @utilGetlockByName(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [255 x i8]
%9 = alloca [70 x i8]
%10 = alloca [50 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 50)
br label %20
17: ; preds = %3
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%19 = call i32 @strncpy(i8* %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 50)
br label %20
20: ; preds = %17, %13
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = getelementptr inbounds [70 x i8], [70 x i8]* %9, i64 0, i64 0
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [70 x i8], [70 x i8]* %9, i64 0, i64 0
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%29 = call i32 @osSystem_GetOutput(i8* %27, i8* %28, i32 255)
br label %37
30: ; preds = %20
%31 = getelementptr inbounds [70 x i8], [70 x i8]* %9, i64 0, i64 0
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [70 x i8], [70 x i8]* %9, i64 0, i64 0
%35 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%36 = call i32 @osSystem_GetOutput(i8* %34, i8* %35, i32 255)
br label %37
37: ; preds = %30, %23
%38 = load i32, i32* %7
ret i32 %38
}

LLVM IR (-O2):
@.str = [24 x i8] c"/var/lock/iptables.lock\00"
@.str.1 = [8 x i8] c"lock %s\00"
@.str.2 = [11 x i8] c"lock -u %s\00"
define i32 @utilGetlockByName(i8* %0, i32* nocapture readnone %1, i32 %2) {
%4 = alloca [255 x i8]
%5 = alloca [70 x i8]
%6 = alloca [50 x i8]
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [70 x i8], [70 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%10 = icmp eq i8* %0, null
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = call i32 @strncpy(i8* %9, i8* %0, i32 50)
br label %15
13: ; preds = %3
%14 = call i32 @strncpy(i8* %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 50)
br label %15
15: ; preds = %13, %11
%16 = icmp eq i32 %2, 0
%17 = select i1 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0)
%18 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) %17, i8* %9)
%19 = call i32 @osSystem_GetOutput(i8* %8, i8* %7, i32 255)
ret i32 0
}