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

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
scalar_t__ strstr(char *, char *);
int http_request(const char *server) {
  FILE *stream;
  char request[1024], buf[1024];
  if (server) {
    sprintf(request, "curl --silent --insecure %s", server);
    stream = popen(request, "r");
    fread(buf, sizeof(char), sizeof(buf), stream);
    pclose(stream);
    if (strstr(buf, "\"last_value\":\"OFF\"") != 0)
      return 2;
    else if (strstr(buf, "\"last_value\":\"ON\"") != 0)
      return 3;
    else
      return EXIT_FAILURE;
  } else {
    return EXIT_FAILURE;
  }
}


x86 assembly (clang, -O0):
<http_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     121e <http_request+0xce>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe84(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
lea    -0x820(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11e4 <http_request+0x94>
movl   $0x2,-0x4(%rbp)
jmp    122a <http_request+0xda>
lea    -0x820(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     120d <http_request+0xbd>
movl   $0x3,-0x4(%rbp)
jmp    122a <http_request+0xda>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122a <http_request+0xda>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_request>:
push   %r14
push   %rbx
sub    $0x808,%rsp
test   %rdi,%rdi
je     11e7 <http_request+0x97>
mov    %rdi,%rdx
lea    0xe93(%rip),%rsi
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
call   1050 <popen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <pclose@plt>
lea    0xe68(%rip),%rsi
mov    %r14,%rdi
call   1070 <strstr@plt>
mov    %rax,%rcx
mov    $0x2,%eax
test   %rcx,%rcx
jne    11f0 <http_request+0xa0>
lea    0xe5f(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strstr@plt>
mov    %rax,%rcx
mov    $0x3,%eax
test   %rcx,%rcx
jne    11f0 <http_request+0xa0>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [28 x i8] c"curl --silent --insecure %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"\22last_value\22:\22OFF\22\00"
@.str.3 = [18 x i8] c"\22last_value\22:\22ON\22\00"
@EXIT_FAILURE = global i32 0
define i32 @http_request(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %31
9: ; preds = %1
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = call i32* @popen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %4
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i32 @fread(i8* %15, i32 1, i32 1024, i32* %16)
%18 = load i32*, i32** %4
%19 = call i32 @pclose(i32* %18)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = call i64 @strstr(i8* %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %9
store i32 2, i32* %2
br label %33
24: ; preds = %9
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i64 @strstr(i8* %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 3, i32* %2
br label %33
29: ; preds = %24
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %2
br label %33
31: ; preds = %1
%32 = load i32, i32* @EXIT_FAILURE
store i32 %32, i32* %2
br label %33
33: ; preds = %31, %29, %28, %23
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [28 x i8] c"curl --silent --insecure %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"\22last_value\22:\22OFF\22\00"
@.str.3 = [18 x i8] c"\22last_value\22:\22ON\22\00"
@EXIT_FAILURE = global i32 0
define i32 @http_request(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 %19, label %7
7: ; preds = %1
%8 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 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 = call i32 @fread(i8* %5, i32 1, i32 1024, i32* %9)
%11 = tail call i32 @pclose(i32* %9)
%12 = call i64 @strstr(i8* %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %7
%15 = call i64 @strstr(i8* %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = load i32, i32* @EXIT_FAILURE
%18 = select i1 %16, i32 %17, i32 3
br label %21
19: ; preds = %1
%20 = load i32, i32* @EXIT_FAILURE
br label %21
21: ; preds = %14, %7, %19
%22 = phi i32 [ %20, %19 ], [ 2, %7 ], [ %18, %14 ]
ret i32 %22
}