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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
char *nssrs_str_join(char, char *, char *);
int /*<<< orphan*/ *stderr;
int mock_resolver(char *tmpdir, char *domain, char *ns) {
  char *file = nssrs_str_join('/', tmpdir, domain);
  FILE *fd = fopen(file, "w");
  int result = 0;
  if (fd != NULL) {
    fprintf(fd, "nameserver %s\n", ns);
    fclose(fd);
    result = 1;
  } else {
    fprintf(stderr, "Unable to write: %s\n", file);
  }
  free(file);
  return result;
}


x86 assembly (clang, -O0):
<mock_resolver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x2f,%edi
call   1070 <nssrs_str_join@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c9 <mock_resolver+0x79>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x2c(%rbp)
jmp    11e3 <mock_resolver+0x93>
mov    0x2e10(%rip),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe33(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mock_resolver>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rdx
mov    %rdi,%rsi
mov    $0x2f,%edi
call   1070 <nssrs_str_join@plt>
mov    %rax,%r15
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a3 <mock_resolver+0x53>
mov    %rax,%rbx
lea    0xe79(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%ebx
jmp    11be <mock_resolver+0x6e>
mov    0x2e36(%rip),%rax
mov    (%rax),%rdi
lea    0xe5d(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [15 x i8] c"nameserver %s\0A\00"
@stderr = global i32* null
@.str.2 = [21 x i8] c"Unable to write: %s\0A\00"
define i32 @mock_resolver(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = call i8* @nssrs_str_join(i8 signext 47, i8* %10, i8* %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %8
store i32 0, i32* %9
%15 = load i32*, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %3
%18 = load i32*, i32** %8
%19 = load i8*, i8** %6
%20 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %8
%22 = call i32 @fclose(i32* %21)
store i32 1, i32* %9
br label %27
23: ; preds = %3
%24 = load i32*, i32** @stderr
%25 = load i8*, i8** %7
%26 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %23, %17
%28 = load i8*, i8** %7
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* %9
ret i32 %30
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [15 x i8] c"nameserver %s\0A\00"
@stderr = global i32* null
@.str.2 = [21 x i8] c"Unable to write: %s\0A\00"
define i32 @mock_resolver(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @nssrs_str_join(i8 signext 47, i8* %0, i8* %1)
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%9 = tail call i32 @fclose(i32* %5)
br label %13
10: ; preds = %3
%11 = load i32*, i32** @stderr
%12 = tail call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ 1, %7 ], [ 0, %10 ]
%15 = tail call i32 @free(i8* %4)
ret i32 %14
}