#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 /*<<< orphan*/ EXIT_FAILURE;
int Is_Valid_IP(char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int system(char *);
void Locate_This_IP(const char *tIP) {
  if (Is_Valid_IP(tIP) != 1) {
    printf("Not a valid IP address\n");
  } else {
    char url[50] = {0};
    strcpy(url, "curl ipinfo.io/");
    strcat(url, tIP);
    char url2[50] = {0};
    strcpy(url2, url);
    strcat(url, "/city");
    int result = system(url);
    if (result == -1 || result == 127) {
      printf("Error: Location could not be resolved\n");
      exit(EXIT_FAILURE);
    }
    strcat(url2, "/country");
    result = system(url2);
    if (result == -1 || result == 127) {
      printf("Error: Location could not be resolved\n");
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<Locate_This_IP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <Is_Valid_IP@plt>
cmp    $0x1,%eax
je     11a2 <Locate_This_IP+0x32>
lea    0xe68(%rip),%rdi
call   1060 <printf@plt>
jmp    1297 <Locate_This_IP+0x127>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1070 <memset@plt>
lea    -0x40(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1070 <memset@plt>
lea    -0x80(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x40(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xffffffff,-0x84(%rbp)
je     1225 <Locate_This_IP+0xb5>
cmpl   $0x7f,-0x84(%rbp)
jne    123f <Locate_This_IP+0xcf>
lea    0xe02(%rip),%rdi
call   1060 <printf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x80(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x80(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xffffffff,-0x84(%rbp)
je     1278 <Locate_This_IP+0x108>
cmpl   $0x7f,-0x84(%rbp)
jne    1292 <Locate_This_IP+0x122>
lea    0xdaf(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1297 <Locate_This_IP+0x127>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Locate_This_IP>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rdi,%rbx
call   1050 <Is_Valid_IP@plt>
cmp    $0x1,%eax
jne    1220 <Locate_This_IP+0xc0>
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movw   $0x0,0x70(%rsp)
lea    0xe68(%rip),%rsi
lea    0x40(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movw   $0x0,0x30(%rsp)
mov    %rsp,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe36(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    %r14,%rdi
call   1060 <system@plt>
cmp    $0x7f,%eax
je     1233 <Locate_This_IP+0xd3>
cmp    $0xffffffff,%eax
je     1233 <Locate_This_IP+0xd3>
lea    0xe1b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
cmp    $0x7f,%eax
je     1233 <Locate_This_IP+0xd3>
cmp    $0xffffffff,%eax
je     1233 <Locate_This_IP+0xd3>
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1e(%rip),%rdi
add    $0x78,%rsp
pop    %rbx
pop    %r14
jmp    1040 <puts@plt>
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Not a valid IP address\0A\00"
@.str.1 = [16 x i8] c"curl ipinfo.io/\00"
@.str.2 = [6 x i8] c"/city\00"
@.str.3 = [39 x i8] c"Error: Location could not be resolved\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [9 x i8] c"/country\00"
define void @Locate_This_IP(i8* %0) {
%2 = alloca i8*
%3 = alloca [50 x i8]
%4 = alloca [50 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @Is_Valid_IP(i8* %6)
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %50
11: ; preds = %1
%12 = bitcast [50 x i8]* %3 to i8*
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%16 = load i8*, i8** %2
%17 = call i32 @strcat(i8* %15, i8* %16)
%18 = bitcast [50 x i8]* %4 to i8*
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%25 = call i32 @system(i8* %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, -1
br i1 %27, label %31, label %28
28: ; preds = %11
%29 = load i32, i32* %5
%30 = icmp eq i32 %29, 127
br i1 %30, label %31, label %35
31: ; preds = %28, %11
%32 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %28
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%38 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%39 = call i32 @system(i8* %38)
store i32 %39, i32* %5
%40 = load i32, i32* %5
%41 = icmp eq i32 %40, -1
br i1 %41, label %45, label %42
42: ; preds = %35
%43 = load i32, i32* %5
%44 = icmp eq i32 %43, 127
br i1 %44, label %45, label %49
45: ; preds = %42, %35
%46 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %42
br label %50
50: ; preds = %49, %9
ret void
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"curl ipinfo.io/\00"
@.str.2 = [6 x i8] c"/city\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [9 x i8] c"/country\00"
@str.5 = [38 x i8] c"Error: Location could not be resolved\00"
@str.6 = [23 x i8] c"Not a valid IP address\00"
define void @Locate_This_IP(i8* %0) {
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
%4 = tail call i32 @Is_Valid_IP(i8* %0)
%5 = icmp eq i32 %4, 1
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
br label %28
8: ; preds = %1
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @strcat(i8* %9, i8* %0)
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%13 = call i32 @strcpy(i8* %12, i8* %9)
%14 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @system(i8* %9)
switch i32 %15, label %20 [
i32 -1, label %16
i32 127, label %16
]
16: ; preds = %8, %8
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %8
%21 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @system(i8* %12)
switch i32 %22, label %27 [
i32 -1, label %23
i32 127, label %23
]
23: ; preds = %20, %20
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %20
br label %28
28: ; preds = %27, %6
ret void
}