#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 atoi(char *);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strtok(char *, char *);
int get_int_param(char *str, char *delim, int index, int *arg) {
  char *buf = malloc(strlen(str) + 1), *token;
  strcpy(buf, str);
  token = strtok(buf, delim);
  while (index > 0 && token != NULL) {
    token = strtok(NULL, delim);
    index--;
  }
  if (token == NULL)
    goto err;
  *arg = atoi(token);
  free(buf);
  return 1;
err:
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<get_int_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x39(%rbp)
jle    11c8 <get_int_param+0x68>
cmpq   $0x0,-0x38(%rbp)
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11d8 <get_int_param+0x78>
jmp    11f7 <get_int_param+0x97>
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <strtok@plt>
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ae <get_int_param+0x4e>
cmpq   $0x0,-0x38(%rbp)
jne    1207 <get_int_param+0xa7>
jmp    122d <get_int_param+0xcd>
mov    -0x38(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    123d <get_int_param+0xdd>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_int_param>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r12
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <strtok@plt>
test   %ebp,%ebp
jle    11bc <get_int_param+0x5c>
xchg   %ax,%ax
test   %rax,%rax
je     11bc <get_int_param+0x5c>
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <strtok@plt>
cmp    $0x2,%ebp
jb     11bc <get_int_param+0x5c>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    11a5 <get_int_param+0x45>
test   %rax,%rax
je     11d3 <get_int_param+0x73>
mov    %rax,%rdi
call   1080 <atoi@plt>
mov    %eax,(%r14)
mov    $0x1,%ebx
jmp    11d5 <get_int_param+0x75>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_int_param(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%12 = load i8*, i8** %6
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %13, 1
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %10
%16 = load i8*, i8** %10
%17 = load i8*, i8** %6
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %10
%20 = load i8*, i8** %7
%21 = call i8* @strtok(i8* %19, i8* %20)
store i8* %21, i8** %11
br label %22
22: ; preds = %30, %4
%23 = load i32, i32* %8
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i8*, i8** %11
%27 = icmp ne i8* %26, null
br label %28
28: ; preds = %25, %22
%29 = phi i1 [ false, %22 ], [ %27, %25 ]
br i1 %29, label %30, label %35
30: ; preds = %28
%31 = load i8*, i8** %7
%32 = call i8* @strtok(i8* null, i8* %31)
store i8* %32, i8** %11
%33 = load i32, i32* %8
%34 = add nsw i32 %33, -1
store i32 %34, i32* %8
br label %22
35: ; preds = %28
%36 = load i8*, i8** %11
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %39
38: ; preds = %35
br label %45
39: ; preds = %35
%40 = load i8*, i8** %11
%41 = call i32 @atoi(i8* %40)
%42 = load i32*, i32** %9
store i32 %41, i32* %42
%43 = load i8*, i8** %10
%44 = call i32 @free(i8* %43)
store i32 1, i32* %5
br label %48
45: ; preds = %38
%46 = load i8*, i8** %10
%47 = call i32 @free(i8* %46)
store i32 0, i32* %5
br label %48
48: ; preds = %45, %39
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
define i32 @get_int_param(i8* %0, i8* nocapture %1, i32 %2, i32* nocapture writeonly %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add nsw i64 %5, 1
%7 = tail call i8* @malloc(i64 %6)
%8 = tail call i32 @strcpy(i8* %7, i8* %0)
%9 = tail call i8* @strtok(i8* %7, i8* %1)
%10 = icmp sgt i32 %2, 0
%11 = icmp ne i8* %9, null
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %20
13: ; preds = %4, %13
%14 = phi i32 [ %16, %13 ], [ %2, %4 ]
%15 = tail call i8* @strtok(i8* null, i8* %1)
%16 = add nsw i32 %14, -1
%17 = icmp ugt i32 %14, 1
%18 = icmp ne i8* %15, null
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %13, label %20
20: ; preds = %13, %4
%21 = phi i8* [ %9, %4 ], [ %15, %13 ]
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @atoi(i8* %21)
store i32 %24, i32* %3
br label %25
25: ; preds = %20, %23
%26 = phi i32 [ 1, %23 ], [ 0, %20 ]
%27 = tail call i32 @free(i8* %7)
ret i32 %26
}