#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_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  scalar_t__ nscount;
};
struct TYPE_4__ {
  TYPE_1__ _ext;
};
struct __res_state {
  int options;
  TYPE_2__ _u;
};

/* Variables and functions */
int RES_INIT;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ res_close();
int res_init();
int /*<<< orphan*/ res_nclose(struct __res_state *);
int res_ninit(struct __res_state *);
int main(int argc, char **argv) {
  int r;
  struct __res_state state;
  r = res_ninit(&state);
  if (r) {
    herror("ninit");
    abort();
  }
  r = res_init();
  if (r) {
    herror("init");
    abort();
  }
  res_close();
  assert(state._u._ext.nscount == 0);
  assert(state.options & RES_INIT);
  res_nclose(&state);
  assert(state._u._ext.nscount == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
call   1060 <res_ninit@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11af <main+0x3f>
lea    0xe5d(%rip),%rdi
call   1090 <herror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1070 <res_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d6 <main+0x66>
lea    0xe37(%rip),%rdi
call   1090 <herror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1050 <res_close@plt>
cmpq   $0x0,-0x20(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x28(%rbp),%edi
mov    0x2de7(%rip),%rax
and    (%rax),%edi
call   1080 <assert@plt>
lea    -0x28(%rbp),%rdi
call   1040 <res_nclose@plt>
cmpq   $0x0,-0x20(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
call   1060 <res_ninit@plt>
test   %eax,%eax
jne    11d9 <main+0x69>
xor    %eax,%eax
call   1070 <res_init@plt>
test   %eax,%eax
jne    11e2 <main+0x72>
xor    %eax,%eax
call   1050 <res_close@plt>
xor    %edi,%edi
cmpq   $0x0,0x10(%rsp)
sete   %dil
call   1080 <assert@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
and    0x8(%rsp),%edi
call   1080 <assert@plt>
lea    0x8(%rsp),%rdi
call   1040 <res_nclose@plt>
xor    %edi,%edi
cmpq   $0x0,0x10(%rsp)
sete   %dil
call   1080 <assert@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe20(%rip),%rdi
jmp    11e9 <main+0x79>
lea    0xe18(%rip),%rdi
call   1090 <herror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.__res_state = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i64 }
@.str = [6 x i8] c"ninit\00"
@.str.1 = [5 x i8] c"init\00"
@RES_INIT = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.__res_state
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @res_ninit(%struct.__res_state* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @herror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %2
%15 = call i32 (...) @res_init()
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @herror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %14
%22 = call i32 (...) @res_close()
%23 = getelementptr inbounds %struct.__res_state, %struct.__res_state* %7, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = getelementptr inbounds %struct.__res_state, %struct.__res_state* %7, i32 0, i32 0
%31 = load i32, i32* %30
%32 = load i32, i32* @RES_INIT
%33 = and i32 %31, %32
%34 = call i32 @assert(i32 %33)
%35 = call i32 @res_nclose(%struct.__res_state* %7)
%36 = getelementptr inbounds %struct.__res_state, %struct.__res_state* %7, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %36, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %37, i32 0, i32 0
%39 = load i64, i64* %38
%40 = icmp eq i64 %39, 0
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
ret i32 0
}

LLVM IR (-O2):
%struct.__res_state = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i64 }
@.str = [6 x i8] c"ninit\00"
@.str.1 = [5 x i8] c"init\00"
@RES_INIT = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.__res_state
%4 = bitcast %struct.__res_state* %3 to i8*
%5 = call i32 @res_ninit(%struct.__res_state* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32 @herror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (...) @abort()
unreachable
10: ; preds = %2
%11 = call i32 (...) @res_init()
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = call i32 @herror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %10
%17 = call i32 (...) @res_close()
%18 = getelementptr inbounds %struct.__res_state, %struct.__res_state* %3, i64 0, i32 1, i32 0, i32 0
%19 = load i64, i64* %18
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = getelementptr inbounds %struct.__res_state, %struct.__res_state* %3, i64 0, i32 0
%24 = load i32, i32* %23
%25 = load i32, i32* @RES_INIT
%26 = and i32 %25, %24
%27 = call i32 @assert(i32 %26)
%28 = call i32 @res_nclose(%struct.__res_state* %3)
%29 = load i64, i64* %18
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
ret i32 0
}