#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *fgets(char *, int, int /*<<< orphan*/ *);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *get_next_parameter(char *buf, int maxsize, FILE *infile, char *inbuf,
                         int init) {
  static char *p;
  if (infile)
    return fgets(buf, maxsize, infile);
  if (inbuf) {
    if (init)
      p = inbuf;
    if (p == NULL || *p == '\0')
      return NULL;
    strncpy(buf, p, maxsize);
    buf[maxsize - 1] = '\0';
    p = strchr(buf, '\n');
    if (p) {
      *p = '\0';
      p++;
    }
    return buf;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<get_next_parameter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     116f <get_next_parameter+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,-0x8(%rbp)
jmp    1235 <get_next_parameter+0x105>
cmpq   $0x0,-0x28(%rbp)
je     122d <get_next_parameter+0xfd>
cmpl   $0x0,-0x2c(%rbp)
je     118f <get_next_parameter+0x5f>
mov    -0x28(%rbp),%rax
mov    %rax,0x2eb1(%rip)
cmpq   $0x0,0x2ea9(%rip)
je     11b0 <get_next_parameter+0x80>
mov    0x2e9c(%rip),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11bd <get_next_parameter+0x8d>
movq   $0x0,-0x8(%rbp)
jmp    1235 <get_next_parameter+0x105>
mov    -0x10(%rbp),%rdi
mov    0x2e78(%rip),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,0x2e4a(%rip)
cmpq   $0x0,0x2e42(%rip)
je     1220 <get_next_parameter+0xf0>
mov    0x2e35(%rip),%rax
movb   $0x0,(%rax)
mov    0x2e2b(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2e20(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <get_next_parameter+0x105>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_parameter>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
test   %rdx,%rdx
je     114d <get_next_parameter+0x1d>
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <fgets@plt>
test   %rcx,%rcx
je     11af <get_next_parameter+0x7f>
test   %r8d,%r8d
je     1160 <get_next_parameter+0x30>
mov    %rcx,0x2ee2(%rip)
jmp    116c <get_next_parameter+0x3c>
mov    0x2ed9(%rip),%rcx
test   %rcx,%rcx
je     11af <get_next_parameter+0x7f>
cmpb   $0x0,(%rcx)
je     11af <get_next_parameter+0x7f>
mov    %rbx,%rdi
mov    %rcx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,0x2ea6(%rip)
test   %rax,%rax
je     11b1 <get_next_parameter+0x81>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,0x2e93(%rip)
jmp    11b1 <get_next_parameter+0x81>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@get_next_parameter.p = internal unnamed_addr global i8* null
define i8* @get_next_parameter(i8* %0, i32 %1, i32* %2, i8* %3, i32 %4) {
%6 = icmp eq i32* %2, null
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i8* @fgets(i8* %0, i32 %1, i32* %2)
br label %30
9: ; preds = %5
%10 = icmp eq i8* %3, null
br i1 %10, label %30, label %11
11: ; preds = %9
%12 = icmp eq i32 %4, 0
br i1 %12, label %14, label %13
13: ; preds = %11
store i8* %3, i8** @get_next_parameter.p
br label %17
14: ; preds = %11
%15 = load i8*, i8** @get_next_parameter.p
%16 = icmp eq i8* %15, null
br i1 %16, label %30, label %17
17: ; preds = %13, %14
%18 = phi i8* [ %3, %13 ], [ %15, %14 ]
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %17
%22 = tail call i32 @strncpy(i8* %0, i8* %18, i32 %1)
%23 = add nsw i32 %1, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %0, i64 %24
store i8 0, i8* %25
%26 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
store i8* %26, i8** @get_next_parameter.p
%27 = icmp eq i8* %26, null
br i1 %27, label %30, label %28
28: ; preds = %21
store i8 0, i8* %26
%29 = getelementptr inbounds i8, i8* %26, i64 1
store i8* %29, i8** @get_next_parameter.p
br label %30
30: ; preds = %9, %21, %28, %14, %17, %7
%31 = phi i8* [ %8, %7 ], [ null, %17 ], [ null, %14 ], [ %0, %28 ], [ %0, %21 ], [ null, %9 ]
ret i8* %31
}