#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 *get_next_arg(char const *, char **);
char *call_start_at_arg(const char *call, int arg_idx) {
  char *offset = (char *)call;
  char *ptr = NULL;
  if (arg_idx > 0) {
    while (arg_idx--) {
      ptr = get_next_arg(call, &offset);
    }
  } else if (arg_idx < 0) {
    return ptr;
  } else if (arg_idx == 1) {
    ptr = get_next_arg(call, &offset);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<call_start_at_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    116d <call_start_at_arg+0x5d>
jmp    113e <call_start_at_arg+0x2e>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1168 <call_start_at_arg+0x58>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <get_next_arg@plt>
mov    %rax,-0x28(%rbp)
jmp    113e <call_start_at_arg+0x2e>
jmp    11a9 <call_start_at_arg+0x99>
cmpl   $0x0,-0x14(%rbp)
jge    1184 <call_start_at_arg+0x74>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b1 <call_start_at_arg+0xa1>
cmpl   $0x1,-0x14(%rbp)
jne    119f <call_start_at_arg+0x8f>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <get_next_arg@plt>
mov    %rax,-0x28(%rbp)
jmp    11a4 <call_start_at_arg+0x94>
jmp    11a9 <call_start_at_arg+0x99>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_start_at_arg>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
test   %esi,%esi
jle    1142 <call_start_at_arg+0x32>
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x8(%rsp),%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <get_next_arg@plt>
add    $0xffffffff,%ebx
jne    1130 <call_start_at_arg+0x20>
jmp    1144 <call_start_at_arg+0x34>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @call_start_at_arg(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
store i8* %8, i8** %6
store i8* null, i8** %7
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %2
br label %12
12: ; preds = %16, %11
%13 = load i32, i32* %5
%14 = add nsw i32 %13, -1
store i32 %14, i32* %5
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i8* @get_next_arg(i8* %17, i8** %6)
store i8* %18, i8** %7
br label %12
19: ; preds = %12
br label %33
20: ; preds = %2
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i8*, i8** %7
store i8* %24, i8** %3
br label %35
25: ; preds = %20
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %4
%30 = call i8* @get_next_arg(i8* %29, i8** %6)
store i8* %30, i8** %7
br label %31
31: ; preds = %28, %25
br label %32
32: ; preds = %31
br label %33
33: ; preds = %32, %19
%34 = load i8*, i8** %7
store i8* %34, i8** %3
br label %35
35: ; preds = %33, %23
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
define i8* @call_start_at_arg(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* %0, i8** %3
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %11
6: ; preds = %2, %6
%7 = phi i32 [ %8, %6 ], [ %1, %2 ]
%8 = add nsw i32 %7, -1
%9 = call i8* @get_next_arg(i8* %0, i8** %3)
%10 = icmp eq i32 %8, 0
br i1 %10, label %11, label %6
11: ; preds = %6, %2
%12 = phi i8* [ null, %2 ], [ %9, %6 ]
ret i8* %12
}