#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*/ command;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fputs(char const *, int /*<<< orphan*/ *);
scalar_t__ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
void popen_nsupdate(const char *priv_key, const char *input) {
  static int tolerance = 5;
  char command[512];
  snprintf(command, sizeof(command), "nsupdate -k %s", priv_key);
  FILE *nsupdate_stdin = popen(command, "we");
  if (!nsupdate_stdin) {
    fprintf(stderr, "Could not popen() nsupdate\n");
    exit(-1);
  }
  if (fputs(input, nsupdate_stdin) == EOF || pclose(nsupdate_stdin)) {
    fprintf(stderr,
            "Unhandled error running nsupdate. Tolerating %d more failures.\n",
            --tolerance);
    if (!tolerance)
      exit(-1);
  }
  usleep(100000);
}


x86 assembly (clang, -O0):
<popen_nsupdate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x200,%esi
lea    0xe66(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x210(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    11e8 <popen_nsupdate+0x78>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x218(%rbp),%rsi
call   1050 <fputs@plt>
mov    0x2de9(%rip),%rcx
cmp    (%rcx),%rax
je     121e <popen_nsupdate+0xae>
mov    -0x218(%rbp),%rdi
call   1030 <pclose@plt>
cmp    $0x0,%rax
je     1260 <popen_nsupdate+0xf0>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    0x2e2b(%rip),%edx
add    $0xffffffff,%edx
mov    %edx,0x2e22(%rip)
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmpl   $0x0,0x2e0d(%rip)
jne    125b <popen_nsupdate+0xeb>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    1260 <popen_nsupdate+0xf0>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<popen_nsupdate>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r14
mov    %rdi,%rcx
lea    0xe79(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1040 <snprintf@plt>
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     1216 <popen_nsupdate+0xa6>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%rax
je     11d2 <popen_nsupdate+0x62>
mov    %rbx,%rdi
call   1030 <pclose@plt>
test   %rax,%rax
je     1201 <popen_nsupdate+0x91>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2e77(%rip),%edx
add    $0xffffffff,%edx
mov    %edx,0x2e6e(%rip)
lea    0xe3d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
cmpl   $0x0,0x2e59(%rip)
je     122d <popen_nsupdate+0xbd>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@popen_nsupdate.tolerance = internal global i32 5
@.str = [15 x i8] c"nsupdate -k %s\00"
@.str.1 = [3 x i8] c"we\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Could not popen() nsupdate\0A\00"
@EOF = global i64 0
@.str.3 = [64 x i8] c"Unhandled error running nsupdate. Tolerating %d more failures.\0A\00"
define void @popen_nsupdate(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [512 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @snprintf(i8* %7, i32 512, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%11 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = load i32*, i32** %6
%21 = call i64 @fputs(i8* %19, i32* %20)
%22 = load i64, i64* @EOF
%23 = icmp eq i64 %21, %22
br i1 %23, label %28, label %24
24: ; preds = %18
%25 = load i32*, i32** %6
%26 = call i64 @pclose(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %24, %18
%29 = load i32, i32* @stderr
%30 = load i32, i32* @popen_nsupdate.tolerance
%31 = add nsw i32 %30, -1
store i32 %31, i32* @popen_nsupdate.tolerance
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @popen_nsupdate.tolerance
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %28
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %28
br label %38
38: ; preds = %37, %24
%39 = call i32 @usleep(i32 100000)
ret void
}

LLVM IR (-O2):
@popen_nsupdate.tolerance = internal unnamed_addr global i32 5
@.str = [15 x i8] c"nsupdate -k %s\00"
@.str.1 = [3 x i8] c"we\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Could not popen() nsupdate\0A\00"
@EOF = global i64 0
@.str.3 = [64 x i8] c"Unhandled error running nsupdate. Tolerating %d more failures.\0A\00"
define void @popen_nsupdate(i8* %0, i8* nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 512, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i32* @popen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = call i64 @fputs(i8* %1, i32* %6)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = call i64 @pclose(i32* %6)
%18 = icmp eq i64 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %16, %12
%20 = load i32, i32* @stderr
%21 = load i32, i32* @popen_nsupdate.tolerance
%22 = add nsw i32 %21, -1
store i32 %22, i32* @popen_nsupdate.tolerance
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @popen_nsupdate.tolerance
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %19, %16
%29 = call i32 @usleep(i32 100000)
ret void
}