#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 scalar_t__ int8_t;
typedef int int16_t;

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
scalar_t__ uexpect(int /*<<< orphan*/, char *, char *, ...);
int8_t esp8266_http_get(char *ip, char *get_str) {
  int8_t retval;
  int16_t len;
  char *msg;
  printf("AT+CIPSTART=\"TCP\",\"%s\",80\r\n", ip);
  retval = uexpect(stdin, "\r\nOK\r\n", "\r\nERROR\r\n", NULL);
  if (retval != 0)
    return retval;
  retval = uexpect(stdin, "Linked\r\n", NULL);
  if (retval != 0)
    return retval;
  len = 60 + strlen(ip) + strlen(get_str);
  msg = malloc(len);
  snprintf(msg, len,
           "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: ESP8266/1.0\r\n\r\n",
           get_str, ip);
  len = strlen(msg);
  printf("AT+CIPSEND=%d\r\n", len);
  retval = uexpect(stdin, "> ", NULL);
  if (retval != 0)
    return retval;
  printf(msg);
  retval = uexpect(stdin, "\r\nSEND OK\r\n", NULL);
  if (retval != 0)
    return retval;
  retval = uexpect(stdin, "\r\nOK\r\n", NULL);
  if (retval != 0)
    return retval;
  printf("AT+CIPCLOSE\r\n");
  retval = uexpect(stdin, "\r\nOK\r\n", NULL);
  if (retval != 0)
    return retval;
  retval = uexpect(stdin, "Unlink\r\n", NULL);
  if (retval != 0)
    return retval;
  return 0;
}


x86 assembly (clang, -O0):
<esp8266_http_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
lea    0xe9a(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   1060 <uexpect@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b0 <esp8266_http_get+0x60>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1381 <esp8266_http_get+0x231>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1060 <uexpect@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e7 <esp8266_http_get+0x97>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1381 <esp8266_http_get+0x231>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x3c,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe0b(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1060 <uexpect@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1284 <esp8266_http_get+0x134>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1381 <esp8266_http_get+0x231>
mov    -0x30(%rbp),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1060 <uexpect@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12c6 <esp8266_http_get+0x176>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1381 <esp8266_http_get+0x231>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1060 <uexpect@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12fd <esp8266_http_get+0x1ad>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1381 <esp8266_http_get+0x231>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
lea    0xd01(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1060 <uexpect@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1342 <esp8266_http_get+0x1f2>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1381 <esp8266_http_get+0x231>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
lea    0xd48(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1060 <uexpect@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1379 <esp8266_http_get+0x229>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1381 <esp8266_http_get+0x231>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<esp8266_http_get>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe8b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e62(%rip),%r12
mov    (%r12),%edi
lea    0xe8b(%rip),%rsi
lea    0xe8b(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   1070 <uexpect@plt>
test   %rax,%rax
jne    1294 <esp8266_http_get+0x134>
mov    (%r12),%edi
lea    0xe78(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <uexpect@plt>
test   %rax,%rax
jne    1294 <esp8266_http_get+0x134>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%ebp
add    $0x3c,%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0xe44(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
mov    %rbx,%r8
call   1060 <snprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0xe5c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%edi
lea    0xe58(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <uexpect@plt>
test   %rax,%rax
jne    1294 <esp8266_http_get+0x134>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%edi
lea    0xe38(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <uexpect@plt>
test   %rax,%rax
jne    1294 <esp8266_http_get+0x134>
mov    (%r12),%edi
lea    0xdbb(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <uexpect@plt>
test   %rax,%rax
jne    1294 <esp8266_http_get+0x134>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
mov    (%r12),%edi
lea    0xd96(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <uexpect@plt>
test   %rax,%rax
je     129d <esp8266_http_get+0x13d>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%edi
lea    0xde4(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <uexpect@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"AT+CIPSTART=\22TCP\22,\22%s\22,80\0D\0A\00"
@stdin = global i32 0
@.str.1 = [7 x i8] c"\0D\0AOK\0D\0A\00"
@.str.2 = [10 x i8] c"\0D\0AERROR\0D\0A\00"
@.str.3 = [9 x i8] c"Linked\0D\0A\00"
@.str.4 = [55 x i8] c"GET %s HTTP/1.1\0D\0AHost: %s\0D\0AUser-Agent: ESP8266/1.0\0D\0A\0D\0A\00"
@.str.5 = [16 x i8] c"AT+CIPSEND=%d\0D\0A\00"
@.str.6 = [3 x i8] c"> \00"
@.str.7 = [12 x i8] c"\0D\0ASEND OK\0D\0A\00"
@.str.8 = [14 x i8] c"AT+CIPCLOSE\0D\0A\00"
@.str.9 = [9 x i8] c"Unlink\0D\0A\00"
define i64 @esp8266_http_get(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @stdin
%12 = call i64 (i32, i8*, i8*, ...) @uexpect(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* null)
store i64 %12, i64* %6
%13 = load i64, i64* %6
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i64, i64* %6
store i64 %16, i64* %3
br label %80
17: ; preds = %2
%18 = load i32, i32* @stdin
%19 = call i64 (i32, i8*, i8*, ...) @uexpect(i32 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* null)
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i64, i64* %6
store i64 %23, i64* %3
br label %80
24: ; preds = %17
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 60, %26
%28 = load i8*, i8** %5
%29 = call i32 @strlen(i8* %28)
%30 = add nsw i32 %27, %29
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = call i8* @malloc(i32 %31)
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = load i32, i32* %7
%35 = load i8*, i8** %5
%36 = load i8*, i8** %4
%37 = call i32 @snprintf(i8* %33, i32 %34, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* %35, i8* %36)
%38 = load i8*, i8** %8
%39 = call i32 @strlen(i8* %38)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = load i32, i32* @stdin
%43 = call i64 (i32, i8*, i8*, ...) @uexpect(i32 %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* null)
store i64 %43, i64* %6
%44 = load i64, i64* %6
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %24
%47 = load i64, i64* %6
store i64 %47, i64* %3
br label %80
48: ; preds = %24
%49 = load i8*, i8** %8
%50 = call i32 (i8*, ...) @printf(i8* %49)
%51 = load i32, i32* @stdin
%52 = call i64 (i32, i8*, i8*, ...) @uexpect(i32 %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* null)
store i64 %52, i64* %6
%53 = load i64, i64* %6
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %48
%56 = load i64, i64* %6
store i64 %56, i64* %3
br label %80
57: ; preds = %48
%58 = load i32, i32* @stdin
%59 = call i64 (i32, i8*, i8*, ...) @uexpect(i32 %58, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* null)
store i64 %59, i64* %6
%60 = load i64, i64* %6
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = load i64, i64* %6
store i64 %63, i64* %3
br label %80
64: ; preds = %57
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%66 = load i32, i32* @stdin
%67 = call i64 (i32, i8*, i8*, ...) @uexpect(i32 %66, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* null)
store i64 %67, i64* %6
%68 = load i64, i64* %6
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %64
%71 = load i64, i64* %6
store i64 %71, i64* %3
br label %80
72: ; preds = %64
%73 = load i32, i32* @stdin
%74 = call i64 (i32, i8*, i8*, ...) @uexpect(i32 %73, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* null)
store i64 %74, i64* %6
%75 = load i64, i64* %6
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %72
%78 = load i64, i64* %6
store i64 %78, i64* %3
br label %80
79: ; preds = %72
store i64 0, i64* %3
br label %80
80: ; preds = %79, %77, %70, %62, %55, %46, %22, %15
%81 = load i64, i64* %3
ret i64 %81
}

LLVM IR (-O2):
@.str = [28 x i8] c"AT+CIPSTART=\22TCP\22,\22%s\22,80\0D\0A\00"
@stdin = global i32 0
@.str.1 = [7 x i8] c"\0D\0AOK\0D\0A\00"
@.str.2 = [10 x i8] c"\0D\0AERROR\0D\0A\00"
@.str.3 = [9 x i8] c"Linked\0D\0A\00"
@.str.4 = [55 x i8] c"GET %s HTTP/1.1\0D\0AHost: %s\0D\0AUser-Agent: ESP8266/1.0\0D\0A\0D\0A\00"
@.str.5 = [16 x i8] c"AT+CIPSEND=%d\0D\0A\00"
@.str.6 = [3 x i8] c"> \00"
@.str.7 = [12 x i8] c"\0D\0ASEND OK\0D\0A\00"
@.str.9 = [9 x i8] c"Unlink\0D\0A\00"
@str = [13 x i8] c"AT+CIPCLOSE\0D\00"
define i64 @esp8266_http_get(i8* %0, i8* %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = load i32, i32* @stdin
%5 = tail call i64 (i32, i8*, i8*, ...) @uexpect(i32 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* null)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %40
7: ; preds = %2
%8 = load i32, i32* @stdin
%9 = tail call i64 (i32, i8*, i8*, ...) @uexpect(i32 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* null)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %40
11: ; preds = %7
%12 = tail call i32 @strlen(i8* %0)
%13 = add nsw i32 %12, 60
%14 = tail call i32 @strlen(i8* %1)
%15 = add nsw i32 %13, %14
%16 = tail call i8* @malloc(i32 %15)
%17 = tail call i32 @snprintf(i8* %16, i32 %15, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %0)
%18 = tail call i32 @strlen(i8* %16)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @stdin
%21 = tail call i64 (i32, i8*, i8*, ...) @uexpect(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* null)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %40
23: ; preds = %11
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %16)
%25 = load i32, i32* @stdin
%26 = tail call i64 (i32, i8*, i8*, ...) @uexpect(i32 %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* null)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %23
%29 = load i32, i32* @stdin
%30 = tail call i64 (i32, i8*, i8*, ...) @uexpect(i32 %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* null)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %28
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%34 = load i32, i32* @stdin
%35 = tail call i64 (i32, i8*, i8*, ...) @uexpect(i32 %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* null)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* @stdin
%39 = tail call i64 (i32, i8*, i8*, ...) @uexpect(i32 %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* null)
br label %40
40: ; preds = %37, %32, %28, %23, %11, %7, %2
%41 = phi i64 [ %5, %2 ], [ %9, %7 ], [ %21, %11 ], [ %26, %23 ], [ %30, %28 ], [ %35, %32 ], [ %39, %37 ]
ret i64 %41
}