#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ *gl_pathv;
  scalar_t__ gl_pathc;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ err(int, char *);
scalar_t__ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int write_to(char *, int /*<<< orphan*/);
int accept_dad_hack(void) {
  int rc = 0, i;
  glob_t gl;
  if (glob("/proc/sys/net/ipv6/conf/*/accept_dad", 0, NULL, &gl) < 0)
    err(1, "failed to create glob");
  for (i = 0; i < (int)gl.gl_pathc; ++i)
    rc |= write_to("0", gl.gl_pathv[i]);
  globfree(&gl);
  return rc;
}


x86 assembly (clang, -O0):
<accept_dad_hack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   1060 <glob@plt>
cmp    $0x0,%rax
jge    1180 <accept_dad_hack+0x40>
mov    $0x1,%edi
lea    0xeaa(%rip),%rsi
call   1050 <err@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    %ecx,%eax
jge    11c1 <accept_dad_hack+0x81>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe93(%rip),%rdi
call   1040 <write_to@plt>
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1187 <accept_dad_hack+0x47>
lea    -0x18(%rbp),%rdi
call   1030 <globfree@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_dad_hack>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%rdi
xor    %r15d,%r15d
mov    %rsp,%rcx
xor    %esi,%esi
xor    %edx,%edx
call   1060 <glob@plt>
test   %rax,%rax
js     116d <accept_dad_hack+0x2d>
cmpl   $0x0,0x8(%rsp)
jg     1185 <accept_dad_hack+0x45>
jmp    11c0 <accept_dad_hack+0x80>
lea    0xeb1(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
cmpl   $0x0,0x8(%rsp)
jle    11c0 <accept_dad_hack+0x80>
xor    %ebx,%ebx
lea    0xead(%rip),%r14
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rax
mov    (%rax,%rbx,4),%esi
mov    %r14,%rdi
call   1040 <write_to@plt>
or     %eax,%r15d
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     11a0 <accept_dad_hack+0x60>
mov    %rsp,%rdi
call   1030 <globfree@plt>
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32*, i64 }
@.str = [37 x i8] c"/proc/sys/net/ipv6/conf/*/accept_dad\00"
@.str.1 = [22 x i8] c"failed to create glob\00"
@.str.2 = [2 x i8] c"0\00"
define i32 @accept_dad_hack() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.TYPE_4__
store i32 0, i32* %1
%4 = call i64 @glob(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 0, i32* null, %struct.TYPE_4__* %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @err(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
store i32 0, i32* %2
br label %9
9: ; preds = %25, %8
%10 = load i32, i32* %2
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 1
%12 = load i64, i64* %11
%13 = trunc i64 %12 to i32
%14 = icmp slt i32 %10, %13
br i1 %14, label %15, label %28
15: ; preds = %9
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 0
%17 = load i32*, i32** %16
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @write_to(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %1
%24 = or i32 %23, %22
store i32 %24, i32* %1
br label %25
25: ; preds = %15
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %9
28: ; preds = %9
%29 = call i32 @globfree(%struct.TYPE_4__* %3)
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32*, i64 }
@.str = [37 x i8] c"/proc/sys/net/ipv6/conf/*/accept_dad\00"
@.str.1 = [22 x i8] c"failed to create glob\00"
@.str.2 = [2 x i8] c"0\00"
define i32 @accept_dad_hack() {
%1 = alloca %struct.TYPE_4__
%2 = bitcast %struct.TYPE_4__* %1 to i8*
%3 = call i64 @glob(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 0, i32* null, %struct.TYPE_4__* %1)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @err(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = trunc i64 %9 to i32
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %7
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 0, i32 0
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %22, %14 ]
%16 = phi i32 [ 0, %12 ], [ %21, %14 ]
%17 = load i32*, i32** %13
%18 = getelementptr inbounds i32, i32* %17, i64 %15
%19 = load i32, i32* %18
%20 = call i32 @write_to(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = or i32 %20, %16
%22 = add nuw nsw i64 %15, 1
%23 = load i64, i64* %8
%24 = shl i64 %23, 32
%25 = ashr exact i64 %24, 32
%26 = icmp slt i64 %22, %25
br i1 %26, label %14, label %27
27: ; preds = %14, %7
%28 = phi i32 [ 0, %7 ], [ %21, %14 ]
%29 = call i32 @globfree(%struct.TYPE_4__* %1)
ret i32 %28
}