#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 */

/* Variables and functions */
int httpget(int, char *, char *, char *, int, int, char *);
int /*<<< orphan*/ log_message(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int tcp_connect(char *, char *);
int redirect(char *argv, int arglen, char *route, int clifd, int hopcount,
             char *Iam) {
  int sockfd;
  int len;
  int i, j;
  char host[128] = {0};
  char port[100] = {0};
  strncpy(host, argv, arglen);
  len = strlen(host);
  for (i = 0; i < len; i++) {
    if (host[i] == ':') {
      host[i] = '\0';
      i++;
      for (j = 0; i < len; i++, j++) {
        if (host[i] == '\n')
          port[i] = '\0';
        else
          port[j] = host[i];
        host[i] = 0;
      }
      port[j + 1] = '\0';
      break;
    }
  }
  sockfd = tcp_connect(host, port);
  if (sockfd >= 0) {
    log_message("record.log", "Connection established successfully!");
  } else {
    return -1;
  }
  switch (httpget(sockfd, host, route, route, clifd, hopcount, Iam)) {
  case 0:
    return 1;
    break;
  case 1:
    return -1;
    break;
  default:
    log_message("record.log", "HTTP GET ERROR！");
    break;
  }
  return -1;
}


x86 assembly (clang, -O0):
<redirect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0xc0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    12a0 <redirect+0x140>
movslq -0x3c(%rbp),%rax
movsbl -0xc0(%rbp,%rax,1),%eax
ff
cmp    $0x3a,%eax
jne    128d <redirect+0x12d>
movslq -0x3c(%rbp),%rax
movb   $0x0,-0xc0(%rbp,%rax,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1278 <redirect+0x118>
movslq -0x3c(%rbp),%rax
movsbl -0xc0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    123f <redirect+0xdf>
movslq -0x3c(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
jmp    1255 <redirect+0xf5>
movslq -0x3c(%rbp),%rax
mov    -0xc0(%rbp,%rax,1),%cl
movslq -0x40(%rbp),%rax
mov    %cl,-0x130(%rbp,%rax,1)
movslq -0x3c(%rbp),%rax
movb   $0x0,-0xc0(%rbp,%rax,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    120d <redirect+0xad>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x130(%rbp,%rax,1)
jmp    12a0 <redirect+0x140>
jmp    1292 <redirect+0x132>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d0 <redirect+0x70>
lea    -0xc0(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1040 <tcp_connect@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     12d8 <redirect+0x178>
lea    0xd39(%rip),%rdi
lea    0xd3d(%rip),%rsi
call   1080 <log_message@plt>
jmp    12e4 <redirect+0x184>
movl   $0xffffffff,-0x4(%rbp)
jmp    1367 <redirect+0x207>
mov    -0x34(%rbp),%edi
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
mov    -0x30(%rbp),%rdx
mov    %rsp,%rax
mov    %rdx,(%rax)
lea    -0xc0(%rbp),%rsi
mov    %rcx,%rdx
call   1070 <httpget@plt>
mov    %eax,%ecx
mov    %ecx,-0x134(%rbp)
test   %eax,%eax
je     1335 <redirect+0x1d5>
jmp    1321 <redirect+0x1c1>
mov    -0x134(%rbp),%eax
sub    $0x1,%eax
je     1341 <redirect+0x1e1>
jmp    134d <redirect+0x1ed>
movl   $0x1,-0x4(%rbp)
jmp    1367 <redirect+0x207>
movl   $0xffffffff,-0x4(%rbp)
jmp    1367 <redirect+0x207>
lea    0xcac(%rip),%rdi
lea    0xcd5(%rip),%rsi
call   1080 <log_message@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redirect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %r9,%r12
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %rdx,%r13
mov    %esi,%edx
mov    %rdi,%rsi
xorps  %xmm0,%xmm0
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movl   $0x0,0xf0(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    12fe <redirect+0x1ae>
mov    %eax,%ecx
xor    %edx,%edx
nopl   0x0(%rax)
cmpb   $0x3a,0x10(%rsp,%rdx,1)
je     1215 <redirect+0xc5>
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1200 <redirect+0xb0>
jmp    12fe <redirect+0x1ae>
movb   $0x0,0x10(%rsp,%rdx,1)
lea    0x1(%rdx),%edi
mov    $0x1,%esi
cmp    %eax,%edi
jge    12f6 <redirect+0x1a6>
lea    -0x2(%rcx),%esi
mov    %edx,%r8d
not    %r8d
add    %eax,%r8d
xor    %r10d,%r10d
cmp    %edx,%esi
jne    124f <redirect+0xff>
mov    %rdx,%rsi
test   $0x1,%r8b
jne    12ce <redirect+0x17e>
jmp    12f1 <redirect+0x1a1>
mov    %r8d,%r9d
and    $0xfffffffe,%r9d
xor    %edi,%edi
nopl   0x0(%rax,%rax,1)
lea    (%rdx,%rdi,1),%rbx
add    $0x1,%rbx
lea    (%rsp,%rdi,1),%rbp
add    $0x10,%rbp
movzbl 0x1(%rdx,%rbp,1),%esi
cmp    $0xa,%sil
cmovne %rdi,%rbx
cmove  %r10d,%esi
mov    %sil,0x90(%rsp,%rbx,1)
movb   $0x0,0x1(%rdx,%rbp,1)
lea    (%rdx,%rdi,1),%rsi
add    $0x2,%rsi
movzbl 0x2(%rdx,%rbp,1),%ebx
lea    0x1(%rdi),%rax
cmp    $0xa,%bl
cmove  %rsi,%rax
cmove  %r10d,%ebx
mov    %bl,0x90(%rsp,%rax,1)
movb   $0x0,0x2(%rdx,%rbp,1)
add    $0x2,%rdi
cmp    %r9,%rdi
jne    1260 <redirect+0x110>
mov    %rdi,%rsi
add    %rdx,%rsi
mov    %rdi,%r10
test   $0x1,%r8b
je     12f1 <redirect+0x1a1>
lea    0x1(%rsi),%rax
movzbl 0x11(%rsp,%rsi,1),%edi
xor    %ebp,%ebp
cmp    $0xa,%dil
cmove  %rax,%r10
cmovne %edi,%ebp
mov    %bpl,0x90(%rsp,%r10,1)
movb   $0x0,0x11(%rsp,%rsi,1)
sub    %edx,%ecx
mov    %rcx,%rsi
movb   $0x0,0x90(%rsp,%rsi,1)
lea    0x10(%rsp),%rdi
lea    0x90(%rsp),%rsi
call   1040 <tcp_connect@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     136d <redirect+0x21d>
mov    %eax,%ebx
lea    0xcde(%rip),%rdi
lea    0xce2(%rip),%rsi
call   1070 <log_message@plt>
mov    %r12,(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    %r13,%rdx
mov    %r13,%rcx
mov    %r15d,%r8d
mov    %r14d,%r9d
call   1060 <httpget@plt>
test   %eax,%eax
je     1368 <redirect+0x218>
cmp    $0x1,%eax
je     136d <redirect+0x21d>
lea    0xca6(%rip),%rdi
lea    0xccf(%rip),%rsi
call   1070 <log_message@plt>
jmp    136d <redirect+0x21d>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"record.log\00"
@.str.1 = [37 x i8] c"Connection established successfully!\00"
@.str.2 = [18 x i8] c"HTTP GET ERROR\EF\BC\81\00"
define i32 @redirect(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [128 x i8]
%19 = alloca [100 x i8]
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
%20 = bitcast [128 x i8]* %18 to i8*
%21 = bitcast [100 x i8]* %19 to i8*
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%23 = load i8*, i8** %8
%24 = load i32, i32* %9
%25 = call i32 @strncpy(i8* %22, i8* %23, i32 %24)
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %15
store i32 0, i32* %16
br label %28
28: ; preds = %83, %6
%29 = load i32, i32* %16
%30 = load i32, i32* %15
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %86
32: ; preds = %28
%33 = load i32, i32* %16
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 58
br i1 %38, label %39, label %82
39: ; preds = %32
%40 = load i32, i32* %16
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 %41
store i8 0, i8* %42
%43 = load i32, i32* %16
%44 = add nsw i32 %43, 1
store i32 %44, i32* %16
store i32 0, i32* %17
br label %45
45: ; preds = %72, %39
%46 = load i32, i32* %16
%47 = load i32, i32* %15
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %77
49: ; preds = %45
%50 = load i32, i32* %16
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 10
br i1 %55, label %56, label %60
56: ; preds = %49
%57 = load i32, i32* %16
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 %58
store i8 0, i8* %59
br label %68
60: ; preds = %49
%61 = load i32, i32* %16
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = load i32, i32* %17
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 %66
store i8 %64, i8* %67
br label %68
68: ; preds = %60, %56
%69 = load i32, i32* %16
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 %70
store i8 0, i8* %71
br label %72
72: ; preds = %68
%73 = load i32, i32* %16
%74 = add nsw i32 %73, 1
store i32 %74, i32* %16
%75 = load i32, i32* %17
%76 = add nsw i32 %75, 1
store i32 %76, i32* %17
br label %45
77: ; preds = %45
%78 = load i32, i32* %17
%79 = add nsw i32 %78, 1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 %80
store i8 0, i8* %81
br label %86
82: ; preds = %32
br label %83
83: ; preds = %82
%84 = load i32, i32* %16
%85 = add nsw i32 %84, 1
store i32 %85, i32* %16
br label %28
86: ; preds = %77, %28
%87 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 0
%89 = call i32 @tcp_connect(i8* %87, i8* %88)
store i32 %89, i32* %14
%90 = load i32, i32* %14
%91 = icmp sge i32 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %86
%93 = call i32 @log_message(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %95
94: ; preds = %86
store i32 -1, i32* %7
br label %109
95: ; preds = %92
%96 = load i32, i32* %14
%97 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%98 = load i8*, i8** %10
%99 = load i8*, i8** %10
%100 = load i32, i32* %11
%101 = load i32, i32* %12
%102 = load i8*, i8** %13
%103 = call i32 @httpget(i32 %96, i8* %97, i8* %98, i8* %99, i32 %100, i32 %101, i8* %102)
switch i32 %103, label %106 [
i32 0, label %104
i32 1, label %105
]
104: ; preds = %95
store i32 1, i32* %7
br label %109
105: ; preds = %95
store i32 -1, i32* %7
br label %109
106: ; preds = %95
%107 = call i32 @log_message(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %108
108: ; preds = %106
store i32 -1, i32* %7
br label %109
109: ; preds = %108, %105, %104, %94
%110 = load i32, i32* %7
ret i32 %110
}

LLVM IR (-O2):
@.str = [11 x i8] c"record.log\00"
@.str.1 = [37 x i8] c"Connection established successfully!\00"
@.str.2 = [18 x i8] c"HTTP GET ERROR\EF\BC\81\00"
define i32 @redirect(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca [128 x i8]
%8 = alloca [100 x i8]
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%11 = call i32 @strncpy(i8* %9, i8* %0, i32 %1)
%12 = call i32 @strlen(i8* %9)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %78
14: ; preds = %6
%15 = zext i32 %12 to i64
br label %16
16: ; preds = %14, %75
%17 = phi i64 [ 0, %14 ], [ %76, %75 ]
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 58
br i1 %20, label %21, label %75
21: ; preds = %16
%22 = trunc i64 %17 to i32
%23 = and i64 %17, 4294967295
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %23
store i8 0, i8* %24
%25 = add nuw nsw i32 %22, 1
%26 = icmp slt i32 %25, %12
br i1 %26, label %27, label %72
27: ; preds = %21
%28 = xor i32 %22, -1
%29 = add i32 %12, %28
%30 = zext i32 %29 to i64
%31 = and i64 %30, 1
%32 = icmp eq i32 %29, 1
br i1 %32, label %57, label %33
33: ; preds = %27
%34 = and i64 %30, 4294967294
br label %35
35: ; preds = %35, %33
%36 = phi i64 [ 0, %33 ], [ %54, %35 ]
%37 = phi i64 [ %17, %33 ], [ %47, %35 ]
%38 = phi i64 [ 0, %33 ], [ %55, %35 ]
%39 = add nuw nsw i64 %37, 1
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 10
%43 = select i1 %42, i64 %39, i64 %36
%44 = select i1 %42, i8 0, i8 %41
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %43
store i8 %44, i8* %45
store i8 0, i8* %40
%46 = or i64 %36, 1
%47 = add nuw nsw i64 %37, 2
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 10
%51 = select i1 %50, i64 %47, i64 %46
%52 = select i1 %50, i8 0, i8 %49
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %51
store i8 %52, i8* %53
store i8 0, i8* %48
%54 = add nuw nsw i64 %36, 2
%55 = add i64 %38, 2
%56 = icmp eq i64 %55, %34
br i1 %56, label %57, label %35
57: ; preds = %35, %27
%58 = phi i64 [ 0, %27 ], [ %54, %35 ]
%59 = phi i64 [ %17, %27 ], [ %47, %35 ]
%60 = icmp eq i64 %31, 0
br i1 %60, label %69, label %61
61: ; preds = %57
%62 = add nuw nsw i64 %59, 1
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = icmp eq i8 %64, 10
%66 = select i1 %65, i64 %62, i64 %58
%67 = select i1 %65, i8 0, i8 %64
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %66
store i8 %67, i8* %68
store i8 0, i8* %63
br label %69
69: ; preds = %57, %61
%70 = sub i32 %12, %22
%71 = zext i32 %70 to i64
br label %72
72: ; preds = %69, %21
%73 = phi i64 [ 1, %21 ], [ %71, %69 ]
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %73
store i8 0, i8* %74
br label %78
75: ; preds = %16
%76 = add nuw nsw i64 %17, 1
%77 = icmp eq i64 %76, %15
br i1 %77, label %78, label %16
78: ; preds = %75, %6, %72
%79 = call i32 @tcp_connect(i8* %9, i8* %10)
%80 = icmp sgt i32 %79, -1
br i1 %80, label %81, label %87
81: ; preds = %78
%82 = call i32 @log_message(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%83 = call i32 @httpget(i32 %79, i8* %9, i8* %2, i8* %2, i32 %3, i32 %4, i8* %5)
switch i32 %83, label %85 [
i32 0, label %87
i32 1, label %84
]
84: ; preds = %81
br label %87
85: ; preds = %81
%86 = call i32 @log_message(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %87
87: ; preds = %81, %78, %85, %84
%88 = phi i32 [ -1, %85 ], [ -1, %84 ], [ -1, %78 ], [ 1, %81 ]
ret i32 %88
}