#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 */
char *malloc(int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *strtok(char *, char *);
char *get_argument(char line[], int argno) {
  char *argument = malloc(512);
  char clone[512];
  strncpy(clone, line, strlen(line) + 1);
  int current_arg = 0;
  char *splitted = strtok(clone, " ");
  while (splitted != NULL) {
    if (splitted[0] != ':') {
      current_arg++;
    }
    if (current_arg == argno + 1) {
      strncpy(argument, splitted, strlen(splitted) + 1);
      return argument;
    }
    splitted = strtok(NULL, " ");
  }
  if (current_arg != argno) {
    argument[0] = '\0';
  }
  return argument;
}


x86 assembly (clang, -O0):
<get_argument>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x200,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x240(%rbp),%rdi
mov    -0x238(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
movl   $0x0,-0x224(%rbp)
lea    -0x220(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x230(%rbp)
je     126c <get_argument+0x12c>
mov    -0x230(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     11f0 <get_argument+0xb0>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
mov    -0x224(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1250 <get_argument+0x110>
mov    -0x20(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    -0x230(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x250(%rbp),%rdi
mov    -0x248(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_argument+0x14a>
xor    %eax,%eax
mov    %eax,%edi
lea    0xda5(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x230(%rbp)
jmp    11c0 <get_argument+0x80>
mov    -0x224(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1282 <get_argument+0x142>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_argument>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    $0x200,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
lea    0xe7b(%rip),%rsi
mov    %r12,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11db <get_argument+0x9b>
mov    %rax,%r13
lea    0x1(%r14),%ebp
xor    %ebx,%ebx
lea    0xe5e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
xor    %ebx,%ebx
cmpb   $0x3a,0x0(%r13)
setne  %bl
add    %eax,%ebx
cmp    %ebp,%ebx
je     11e8 <get_argument+0xa8>
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11b0 <get_argument+0x70>
cmp    %r14d,%ebx
jne    11e2 <get_argument+0xa2>
jmp    11ff <get_argument+0xbf>
xor    %ebx,%ebx
cmp    %r14d,%ebx
je     11ff <get_argument+0xbf>
movb   $0x0,(%r15)
jmp    11ff <get_argument+0xbf>
mov    %r13,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <strncpy@plt>
mov    %r15,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @get_argument(i8* %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add nsw i64 %6, 1
%8 = call i32 @strncpy(i8* %5, i8* %0, i64 %7)
%9 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %28, label %11
11: ; preds = %2
%12 = add nsw i32 %1, 1
br label %13
13: ; preds = %11, %25
%14 = phi i8* [ %9, %11 ], [ %26, %25 ]
%15 = phi i32 [ 0, %11 ], [ %19, %25 ]
%16 = load i8, i8* %14
%17 = icmp ne i8 %16, 58
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %15, %18
%20 = icmp eq i32 %19, %12
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = call i64 @strlen(i8* %14)
%23 = add nsw i64 %22, 1
%24 = call i32 @strncpy(i8* %4, i8* %14, i64 %23)
br label %32
25: ; preds = %13
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %13
28: ; preds = %25, %2
%29 = phi i32 [ 0, %2 ], [ %19, %25 ]
%30 = icmp eq i32 %29, %1
br i1 %30, label %32, label %31
31: ; preds = %28
store i8 0, i8* %4
br label %32
32: ; preds = %28, %31, %21
ret i8* %4
}