#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 *malloc(int);
char *strdup(char *);
unsigned int strlen(char *);
char *strsep(char **, char *);
int *get_servers_ports(char **servers_list, int servers_amount) {
  char *server_raw, *port_string;
  int server_port;
  int *servers_ports = malloc(1024 * sizeof(int *));
  unsigned int i, j;
  for (i = 0; i < servers_amount; i++) {
    server_raw = strdup(servers_list[i]);
    strsep(&server_raw, ":");
    port_string = strsep(&server_raw, ":");
    server_port = 0;
    for (j = 0; j < strlen(port_string); j++) {
      server_port = server_port * 10 + (port_string[j] - '0');
    }
    servers_ports[i] = server_port;
  }
  return servers_ports;
}


x86 assembly (clang, -O0):
<get_servers_ports>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x2000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1212 <get_servers_ports+0xd2>
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1050 <strsep@plt>
lea    -0x18(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jae    11f7 <get_servers_ports+0xb7>
imul   $0xa,-0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11b6 <get_servers_ports+0x76>
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1164 <get_servers_ports+0x24>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_servers_ports>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %rdi,0x18(%rsp)
mov    $0x2000,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %ebx,%ebx
je     1218 <get_servers_ports+0xd8>
mov    %ebx,%eax
mov    %rax,0x10(%rsp)
xor    %r14d,%r14d
lea    0xe83(%rip),%r12
lea    0x20(%rsp),%r13
jmp    11a4 <get_servers_ports+0x64>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%rax
mov    %r15d,(%rax,%r14,4)
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     1218 <get_servers_ports+0xd8>
mov    0x18(%rsp),%rax
mov    (%rax,%r14,8),%rdi
call   1060 <strdup@plt>
mov    %rax,0x20(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <strsep@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <strsep@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    $0x0,%r15d
test   %eax,%eax
je     1190 <get_servers_ports+0x50>
xor    %ebp,%ebp
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
lea    (%r15,%r15,4),%eax
movsbl (%rbx,%rbp,1),%ecx
lea    (%rcx,%rax,2),%r15d
add    $0xffffffd0,%r15d
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbp
jb     11f0 <get_servers_ports+0xb0>
jmp    1190 <get_servers_ports+0x50>
mov    0x8(%rsp),%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
define i32* @get_servers_ports(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%11 = call i32* @malloc(i32 8192)
store i32* %11, i32** %8
store i32 0, i32* %9
br label %12
12: ; preds = %50, %2
%13 = load i32, i32* %9
%14 = load i32, i32* %4
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %53
16: ; preds = %12
%17 = load i8**, i8*** %3
%18 = load i32, i32* %9
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i8* @strdup(i8* %21)
store i8* %22, i8** %5
%23 = call i8* @strsep(i8** %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = call i8* @strsep(i8** %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %24, i8** %6
store i32 0, i32* %7
store i32 0, i32* %10
br label %25
25: ; preds = %41, %16
%26 = load i32, i32* %10
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
%29 = icmp ult i32 %26, %28
br i1 %29, label %30, label %44
30: ; preds = %25
%31 = load i32, i32* %7
%32 = mul nsw i32 %31, 10
%33 = load i8*, i8** %6
%34 = load i32, i32* %10
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = sub nsw i32 %38, 48
%40 = add nsw i32 %32, %39
store i32 %40, i32* %7
br label %41
41: ; preds = %30
%42 = load i32, i32* %10
%43 = add i32 %42, 1
store i32 %43, i32* %10
br label %25
44: ; preds = %25
%45 = load i32, i32* %7
%46 = load i32*, i32** %8
%47 = load i32, i32* %9
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
br label %50
50: ; preds = %44
%51 = load i32, i32* %9
%52 = add i32 %51, 1
store i32 %52, i32* %9
br label %12
53: ; preds = %12
%54 = load i32*, i32** %8
ret i32* %54
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
define noalias i32* @get_servers_ports(i8** nocapture %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i32* @malloc(i32 8192)
%6 = icmp eq i32 %1, 0
br i1 %6, label %36, label %7
7: ; preds = %2
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %31
%10 = phi i64 [ 0, %7 ], [ %34, %31 ]
%11 = getelementptr inbounds i8*, i8** %0, i64 %10
%12 = load i8*, i8** %11
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %3
%14 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @strlen(i8* %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %31, label %18
18: ; preds = %9, %18
%19 = phi i64 [ %27, %18 ], [ 0, %9 ]
%20 = phi i32 [ %26, %18 ], [ 0, %9 ]
%21 = mul nsw i32 %20, 10
%22 = getelementptr inbounds i8, i8* %15, i64 %19
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = add i32 %21, -48
%26 = add i32 %25, %24
%27 = add nuw nsw i64 %19, 1
%28 = call i32 @strlen(i8* %15)
%29 = zext i32 %28 to i64
%30 = icmp ult i64 %27, %29
br i1 %30, label %18, label %31
31: ; preds = %18, %9
%32 = phi i32 [ 0, %9 ], [ %26, %18 ]
%33 = getelementptr inbounds i32, i32* %5, i64 %10
store i32 %32, i32* %33
%34 = add nuw nsw i64 %10, 1
%35 = icmp eq i64 %34, %8
br i1 %35, label %36, label %9
36: ; preds = %31, %2
ret i32* %5
}