#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
int gettok(char *line, char *dest, int size, int eatspace) {
  int bpos, epos, eaten;
  char *t;
  bpos = strchr(line, '[') - line;
  if (bpos < 0) {
    fprintf(stderr, "Extraneous newline in file.  Exiting.");
    exit(1);
  }
  line += 1 + bpos;
  epos = strchr(line, ']') - line;
  if (epos < 0) {
    fprintf(stderr, "Extraneous newline in file.  Exiting.");
    exit(1);
  }
  line[epos] = '\0';
  eaten = bpos + epos + 1;
  if (eatspace)
    if ((t = strchr(line, ' ')))
      *t = 0;
  strncpy(dest, line, size);
  return eaten + 1;
}


x86 assembly (clang, -O0):
<gettok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5b,%esi
call   1040 <strchr@plt>
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1197 <gettok+0x57>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5d,%esi
call   1040 <strchr@plt>
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11ec <gettok+0xac>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1236 <gettok+0xf6>
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1231 <gettok+0xf1>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    1236 <gettok+0xf6>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettok>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x5b,%esi
call   1040 <strchr@plt>
mov    %rax,%r13
sub    %rbx,%r13
test   %r13d,%r13d
js     11d1 <gettok+0x91>
mov    %r13d,%eax
add    $0x1,%eax
cltq
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x5d,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
sub    %rbx,%rbp
test   %ebp,%ebp
js     11d1 <gettok+0x91>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
test   %r12d,%r12d
je     11af <gettok+0x6f>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11af <gettok+0x6f>
movb   $0x0,(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
lea    0x2(%r13,%rbp,1),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"Extraneous newline in file. Exiting.\00"
define i32 @gettok(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i8*, i8** %5
%14 = call i8* @strchr(i8* %13, i8 signext 91)
%15 = load i8*, i8** %5
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %4
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %4
%27 = load i32, i32* %9
%28 = add nsw i32 1, %27
%29 = load i8*, i8** %5
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = call i8* @strchr(i8* %32, i8 signext 93)
%34 = load i8*, i8** %5
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %26
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %26
%46 = load i8*, i8** %5
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
%50 = load i32, i32* %9
%51 = load i32, i32* %10
%52 = add nsw i32 %50, %51
%53 = add nsw i32 %52, 1
store i32 %53, i32* %11
%54 = load i32, i32* %8
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %63
56: ; preds = %45
%57 = load i8*, i8** %5
%58 = call i8* @strchr(i8* %57, i8 signext 32)
store i8* %58, i8** %12
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = load i8*, i8** %12
store i8 0, i8* %61
br label %62
62: ; preds = %60, %56
br label %63
63: ; preds = %62, %45
%64 = load i8*, i8** %6
%65 = load i8*, i8** %5
%66 = load i32, i32* %7
%67 = call i32 @strncpy(i8* %64, i8* %65, i32 %66)
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
ret i32 %69
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"Extraneous newline in file. Exiting.\00"
define i32 @gettok(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 91)
%6 = ptrtoint i8* %5 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = trunc i64 %8 to i32
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %4
%16 = shl i64 %8, 32
%17 = add i64 %16, 4294967296
%18 = ashr exact i64 %17, 32
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = tail call i8* @strchr(i8* dereferenceable(1) %19, i8 signext 93)
%21 = ptrtoint i8* %20 to i64
%22 = ptrtoint i8* %19 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %15
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %15
%31 = shl i64 %23, 32
%32 = ashr exact i64 %31, 32
%33 = getelementptr inbounds i8, i8* %19, i64 %32
store i8 0, i8* %33
%34 = icmp eq i32 %3, 0
br i1 %34, label %39, label %35
35: ; preds = %30
%36 = tail call i8* @strchr(i8* dereferenceable(1) %19, i8 signext 32)
%37 = icmp eq i8* %36, null
br i1 %37, label %39, label %38
38: ; preds = %35
store i8 0, i8* %36
br label %39
39: ; preds = %35, %38, %30
%40 = tail call i32 @strncpy(i8* %1, i8* %19, i32 %2)
%41 = add nuw i32 %9, 2
%42 = add i32 %41, %24
ret i32 %42
}