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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  char path[1035];
  fp = popen("wget -q -O - "
             "http://localhost:47800/api/v1/bacnet/devices/1000/objects/0.12",
             "r");
  if (fp == NULL) {
    printf("Failed to run command\n");
    exit(1);
  }
  while (fgets(path, sizeof(path), fp) != NULL) {
    printf("%s", path);
  }
  pclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
lea    0xed5(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a3 <main+0x53>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11a8 <main+0x58>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x40b,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11e1 <main+0x91>
lea    -0x430(%rbp),%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a8 <main+0x58>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
lea    0xe8d(%rip),%rdi
lea    0xed2(%rip),%rsi
call   1070 <popen@plt>
test   %rax,%rax
je     11e9 <main+0x89>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x40b,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d2 <main+0x72>
lea    0xeab(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x40b,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
mov    %r15,%rdi
call   1050 <pclose@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [76 x i8] c"wget -q -O - http://localhost:47800/api/v1/bacnet/devices/1000/objects/0.12\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Failed to run command\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1035 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @popen(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
br label %15
15: ; preds = %20, %14
%16 = getelementptr inbounds [1035 x i8], [1035 x i8]* %7, i64 0, i64 0
%17 = load i32*, i32** %6
%18 = call i32* @fgets(i8* %16, i32 1035, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = getelementptr inbounds [1035 x i8], [1035 x i8]* %7, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %15
23: ; preds = %15
%24 = load i32*, i32** %6
%25 = call i32 @pclose(i32* %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [76 x i8] c"wget -q -O - http://localhost:47800/api/v1/bacnet/devices/1000/objects/0.12\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@str = [22 x i8] c"Failed to run command\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1035 x i8]
%4 = getelementptr inbounds [1035 x i8], [1035 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @popen(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 1035, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %17, label %13
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %13
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%15 = call i32* @fgets(i8* %4, i32 1035, i32* %5)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %13
17: ; preds = %13, %7
%18 = call i32 @pclose(i32* %5)
ret i32 0
}