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

/* Variables and functions */
unsigned int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
void gtw_run(void *run_data) {
  FILE *fp;
  unsigned int bytes_read = 0;
  unsigned int bytes_written = 0;
  char cmd[1024];
  char result[1024];
  if (run_data == NULL) {
    goto DONE;
  }
  snprintf(cmd, sizeof(cmd), "dig +short %s", (char *)run_data);
  fp = popen(cmd, "r");
  if (fp == NULL) {
    goto DONE;
  }
  while ((bytes_read = fread(result + bytes_written, sizeof(char),
                             (sizeof(result) - bytes_written - 1), fp)) != 0) {
    bytes_written += bytes_read;
  }
  result[bytes_written] = '\0';
  pclose(fp);
  printf("%s\n%s\n", (char *)run_data, result);
DONE:
  free(run_data);
  return;
}


x86 assembly (clang, -O0):
<gtw_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118d <gtw_run+0x2d>
jmp    1248 <gtw_run+0xe8>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x400,%esi
lea    0xe5c(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d0 <gtw_run+0x70>
jmp    1248 <gtw_run+0xe8>
jmp    11d5 <gtw_run+0x75>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%eax
add    %rax,%rdi
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
mov    $0x400,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     121d <gtw_run+0xbd>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11d5 <gtw_run+0x75>
mov    -0x18(%rbp),%eax
movb   $0x0,-0x820(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
call   1060 <pclose@plt>
mov    -0x8(%rbp),%rsi
lea    -0x820(%rbp),%rdx
lea    0xdcd(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtw_run>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%r14
test   %rdi,%rdi
je     11f0 <gtw_run+0x90>
lea    0xe84(%rip),%rdx
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rcx
call   1070 <snprintf@plt>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1080 <popen@plt>
test   %rax,%rax
je     11f0 <gtw_run+0x90>
mov    %rax,%r15
xor    %ebp,%ebp
nopl   (%rax)
mov    %ebp,%eax
lea    (%rsp,%rax,1),%rbx
mov    $0x3ff,%edx
sub    %ebp,%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1040 <fread@plt>
add    %eax,%ebp
test   %eax,%eax
jne    11b0 <gtw_run+0x50>
movb   $0x0,(%rbx)
mov    %r15,%rdi
call   1060 <pclose@plt>
lea    0xe2b(%rip),%rdi
mov    %rsp,%rdx
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"dig +short %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"%s\0A%s\0A\00"
define void @gtw_run(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %5
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
br label %47
11: ; preds = %1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = call i32 @snprintf(i8* %12, i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = call i32* @popen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %3
%17 = load i32*, i32** %3
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %11
br label %47
20: ; preds = %11
br label %21
21: ; preds = %34, %20
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%23 = load i32, i32* %5
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i32, i32* %5
%27 = zext i32 %26 to i64
%28 = sub i64 1024, %27
%29 = sub i64 %28, 1
%30 = trunc i64 %29 to i32
%31 = load i32*, i32** %3
%32 = call i32 @fread(i8* %25, i32 1, i32 %30, i32* %31)
store i32 %32, i32* %4
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %21
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = add i32 %36, %35
store i32 %37, i32* %5
br label %21
38: ; preds = %21
%39 = load i32, i32* %5
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %40
store i8 0, i8* %41
%42 = load i32*, i32** %3
%43 = call i32 @pclose(i32* %42)
%44 = load i8*, i8** %2
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %45)
br label %47
47: ; preds = %38, %19, %10
%48 = load i8*, i8** %2
%49 = call i32 @free(i8* %48)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"dig +short %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"%s\0A%s\0A\00"
define void @gtw_run(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %22, label %7
7: ; preds = %1
%8 = call i32 @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32* @popen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %22, label %11
11: ; preds = %7, %11
%12 = phi i32 [ %18, %11 ], [ 0, %7 ]
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %13
%15 = sub i32 1023, %12
%16 = call i32 @fread(i8* %14, i32 1, i32 %15, i32* %9)
%17 = icmp eq i32 %16, 0
%18 = add i32 %16, %12
br i1 %17, label %19, label %11
19: ; preds = %11
store i8 0, i8* %14
%20 = call i32 @pclose(i32* %9)
%21 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %5)
br label %22
22: ; preds = %7, %1, %19
%23 = call i32 @free(i8* %0)
ret void
}