#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 sscanf(char *, char *, int *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int GetIntParams(int argc, char **argv, int *argn, char *pos, int numParams,
                 int *params) {
  int i;
  char *st, buf[256];
  i = 0;
  strcpy(buf, pos);
  st = strtok(buf, "\t,/");
  do {
    if (st == NULL) {
      if ((*argn) + 1 < argc) {
        (*argn)++;
        strcpy(buf, argv[*argn]);
      } else
        return -1;
      st = strtok(buf, "\t,/");
      if (st == NULL)
        return -1;
    }
    if (sscanf(st, "%d", params + i) != 1)
      return -1;
    i++;
    if (i < numParams)
      st = strtok(NULL, "\t,/");
  } while (i < numParams);
  return 0;
}


x86 assembly (clang, -O0):
<GetIntParams>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x140(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x140(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1207 <GetIntParams+0xd7>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    11c8 <GetIntParams+0x98>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
lea    -0x140(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
jmp    11d4 <GetIntParams+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    127c <GetIntParams+0x14c>
lea    -0x140(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1202 <GetIntParams+0xd2>
movl   $0xffffffff,-0x4(%rbp)
jmp    127c <GetIntParams+0x14c>
jmp    1207 <GetIntParams+0xd7>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rdx
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xde3(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     123b <GetIntParams+0x10b>
movl   $0xffffffff,-0x4(%rbp)
jmp    127c <GetIntParams+0x14c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1264 <GetIntParams+0x134>
xor    %eax,%eax
mov    %eax,%edi
lea    0xda5(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x40(%rbp)
jmp    1269 <GetIntParams+0x139>
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     1180 <GetIntParams+0x50>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetIntParams>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %r9,%r14
mov    %r8d,%r15d
mov    %rdx,0x18(%rsp)
mov    %rsi,0x10(%rsp)
mov    %edi,0xc(%rsp)
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    %rcx,%rsi
call   1030 <strcpy@plt>
lea    0xe94(%rip),%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <strtok@plt>
cmp    $0x2,%r15d
mov    $0x1,%r13d
cmovge %r15d,%r13d
add    $0xffffffff,%r13d
lea    0xe74(%rip),%rbp
mov    $0xffffffff,%r12d
test   %rax,%rax
jne    11da <GetIntParams+0xaa>
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rdx
movslq (%rdx),%rax
lea    0x1(%rax),%ecx
cmp    0xc(%rsp),%ecx
jge    1213 <GetIntParams+0xe3>
mov    %ecx,(%rdx)
mov    0x10(%rsp),%rcx
mov    0x8(%rcx,%rax,8),%rsi
lea    0x20(%rsp),%r15
mov    %r15,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     1213 <GetIntParams+0xe3>
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1208 <GetIntParams+0xd8>
sub    $0x1,%r13
jb     1210 <GetIntParams+0xe0>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
add    $0x4,%r14
test   %rax,%rax
jne    11da <GetIntParams+0xaa>
jmp    11a0 <GetIntParams+0x70>
mov    $0xffffffff,%r12d
jmp    1213 <GetIntParams+0xe3>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\09,/\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @GetIntParams(i32 %0, i8** %1, i32* %2, i8* %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca [256 x i8]
store i32 %0, i32* %8
store i8** %1, i8*** %9
store i32* %2, i32** %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32* %5, i32** %13
store i32 0, i32* %14
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%18 = load i8*, i8** %11
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%21 = call i8* @strtok(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %15
br label %22
22: ; preds = %69, %6
%23 = load i8*, i8** %15
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %51
25: ; preds = %22
%26 = load i32*, i32** %10
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %43
31: ; preds = %25
%32 = load i32*, i32** %10
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1
store i32 %34, i32* %32
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%36 = load i8**, i8*** %9
%37 = load i32*, i32** %10
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %36, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 @strcpy(i8* %35, i8* %41)
br label %44
43: ; preds = %25
store i32 -1, i32* %7
br label %74
44: ; preds = %31
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%46 = call i8* @strtok(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %46, i8** %15
%47 = load i8*, i8** %15
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %50
49: ; preds = %44
store i32 -1, i32* %7
br label %74
50: ; preds = %44
br label %51
51: ; preds = %50, %22
%52 = load i8*, i8** %15
%53 = load i32*, i32** %13
%54 = load i32, i32* %14
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = call i32 @sscanf(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %56)
%58 = icmp ne i32 %57, 1
br i1 %58, label %59, label %60
59: ; preds = %51
store i32 -1, i32* %7
br label %74
60: ; preds = %51
%61 = load i32, i32* %14
%62 = add nsw i32 %61, 1
store i32 %62, i32* %14
%63 = load i32, i32* %14
%64 = load i32, i32* %12
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %68
66: ; preds = %60
%67 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %67, i8** %15
br label %68
68: ; preds = %66, %60
br label %69
69: ; preds = %68
%70 = load i32, i32* %14
%71 = load i32, i32* %12
%72 = icmp slt i32 %70, %71
br i1 %72, label %22, label %73
73: ; preds = %69
store i32 0, i32* %7
br label %74
74: ; preds = %73, %59, %49, %43
%75 = load i32, i32* %7
ret i32 %75
}

LLVM IR (-O2):
@.str = [4 x i8] c"\09,/\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @GetIntParams(i32 %0, i8** nocapture %1, i32* nocapture %2, i8* %3, i32 %4, i32* %5) {
%7 = alloca [256 x i8]
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* %3)
%10 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @llvm.smax.i32(i32 %4, i32 1)
%12 = add nsw i32 %11, -1
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %36, %6
%15 = phi i64 [ %37, %36 ], [ 0, %6 ]
%16 = phi i8* [ %38, %36 ], [ %10, %6 ]
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
%21 = icmp slt i32 %20, %0
br i1 %21, label %22, label %39
22: ; preds = %18
store i32 %20, i32* %2
%23 = sext i32 %20 to i64
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @strcpy(i8* %8, i8* %25)
%27 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %39, label %29
29: ; preds = %22, %14
%30 = phi i8* [ %27, %22 ], [ %16, %14 ]
%31 = getelementptr inbounds i32, i32* %5, i64 %15
%32 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %31)
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = icmp eq i64 %15, %13
br i1 %35, label %39, label %36
36: ; preds = %34
%37 = add nuw nsw i64 %15, 1
%38 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %14
39: ; preds = %34, %29, %22, %18
%40 = phi i32 [ -1, %18 ], [ -1, %22 ], [ -1, %29 ], [ 0, %34 ]
ret i32 %40
}