#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 EOF;
int getop(char *);
int matoi(char *);
int matoi2(char *);
int mgetline(char *, int const);
int /*<<< orphan*/ mitoa(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int strindex(char *, char *);
int main(void) {
  const int LIMIT = 20;
  char sgetline[LIMIT];
  printf("\n===============\n");
  printf("getline (waiting for input):\n");
  printf("\tgot %i characters\n", mgetline(sgetline, LIMIT));
  printf("\tgot this: %s\n", sgetline);
  char *satoi = "325abc";
  printf("\n===============\n");
  printf("atoi:\n");
  printf("\tfound '%i' in '%s'\n", matoi(satoi), satoi);
  char *satoi2 = "   -325abc";
  printf("\n===============\n");
  printf("atoi version 2:\n");
  printf("\tfound '%i' in '%s'\n", matoi2(satoi2), satoi2);
  int iitoa = 12345;
  char sitoa[20];
  printf("\n===============\n");
  printf("itoa:\n");
  mitoa(iitoa, sitoa);
  printf("\tfound '%s' in '%i'\n", sitoa, iitoa);
  char *sstr = "Good Morning!";
  char *tstr = "ning";
  printf("\n===============\n");
  printf("strindex:\n");
  printf("\tfound '%s' at position %i in '%s'\n", tstr, strindex(sstr, tstr),
         sstr);
  int type;
  char s[100];
  printf("\n===============\n");
  printf("getop (waiting for input):\n");
  while ((type = getop(s)) != EOF)
    if (type == '0')
      printf("\tnumber\n");
    else
      printf("\t%c\n", type);
  printf("\n\nDone.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x14,-0x8(%rbp)
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xe0(%rbp),%rdi
mov    $0x14,%esi
call   1080 <mgetline@plt>
mov    %eax,%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe70(%rip),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <matoi@plt>
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe42(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <matoi2@plt>
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3039,-0x24(%rbp)
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1090 <mitoa@plt>
lea    -0x40(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdf2(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xdf5(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1060 <strindex@plt>
mov    -0xe8(%rbp),%rsi
mov    %eax,%edx
mov    -0x48(%rbp),%rcx
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xc0(%rbp),%rdi
call   1050 <getop@plt>
mov    %eax,-0x54(%rbp)
mov    0x2ca3(%rip),%rcx
cmp    (%rcx),%eax
je     1380 <main+0x210>
cmpl   $0x30,-0x54(%rbp)
jne    136a <main+0x1fa>
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    137b <main+0x20b>
mov    -0x54(%rbp),%esi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    132f <main+0x1bf>
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0xf42(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xef0(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1090 <mgetline@plt>
lea    0xe40(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe44(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe47(%rip),%rbx
mov    %rbx,%rdi
call   1080 <matoi@plt>
lea    0xe1f(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
lea    0xe0a(%rip),%rbx
mov    %rbx,%rdi
call   1050 <matoi2@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%rbx
mov    $0x3039,%edi
mov    %rbx,%rsi
call   10a0 <mitoa@plt>
lea    0xdd1(%rip),%rdi
mov    %rbx,%rsi
mov    $0x3039,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
lea    0xdbc(%rip),%r15
lea    0xdc3(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <strindex@plt>
lea    0xdb6(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
lea    0x40(%rsp),%rdi
call   1060 <getop@plt>
mov    0x2cff(%rip),%r12
cmp    (%r12),%eax
jne    130c <main+0x18c>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdf8(%rip),%r14
lea    0x40(%rsp),%rbx
lea    0xd70(%rip),%r15
jmp    134a <main+0x1ca>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <getop@plt>
cmp    (%r12),%eax
je     12ef <main+0x16f>
cmp    $0x30,%eax
jne    1330 <main+0x1b0>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    133c <main+0x1bc>

LLVM IR (-O0):
@.str = [18 x i8] c"\0A===============\0A\00"
@.str.1 = [30 x i8] c"getline (waiting for input):\0A\00"
@.str.2 = [20 x i8] c"\09got %i characters\0A\00"
@.str.3 = [15 x i8] c"\09got this: %s\0A\00"
@.str.4 = [7 x i8] c"325abc\00"
@.str.5 = [7 x i8] c"atoi:\0A\00"
@.str.6 = [21 x i8] c"\09found '%i' in '%s'\0A\00"
@.str.7 = [11 x i8] c" -325abc\00"
@.str.8 = [17 x i8] c"atoi version 2:\0A\00"
@.str.9 = [7 x i8] c"itoa:\0A\00"
@.str.10 = [21 x i8] c"\09found '%s' in '%i'\0A\00"
@.str.11 = [14 x i8] c"Good Morning!\00"
@.str.12 = [5 x i8] c"ning\00"
@.str.13 = [11 x i8] c"strindex:\0A\00"
@.str.14 = [36 x i8] c"\09found '%s' at position %i in '%s'\0A\00"
@.str.15 = [28 x i8] c"getop (waiting for input):\0A\00"
@EOF = global i32 0
@.str.16 = [9 x i8] c"\09number\0A\00"
@.str.17 = [5 x i8] c"\09%c\0A\00"
@.str.18 = [9 x i8] c"\0A\0ADone.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [20 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [100 x i8]
store i32 0, i32* %1
store i32 20, i32* %2
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i8, i64 20
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @mgetline(i8* %13, i32 20)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %13)
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%21 = load i8*, i8** %4
%22 = call i32 @matoi(i8* %21)
%23 = load i8*, i8** %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %22, i8* %23)
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8** %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%27 = load i8*, i8** %5
%28 = call i32 @matoi2(i8* %27)
%29 = load i8*, i8** %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %28, i8* %29)
store i32 12345, i32* %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%33 = load i32, i32* %6
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%35 = call i32 @mitoa(i32 %33, i8* %34)
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%37 = load i32, i32* %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i8* %36, i32 %37)
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i8** %9
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.13, i64 0, i64 0))
%41 = load i8*, i8** %9
%42 = load i8*, i8** %8
%43 = load i8*, i8** %9
%44 = call i32 @strindex(i8* %42, i8* %43)
%45 = load i8*, i8** %8
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0), i8* %41, i32 %44, i8* %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0))
br label %49
49: ; preds = %62, %0
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%51 = call i32 @getop(i8* %50)
store i32 %51, i32* %10
%52 = load i32, i32* @EOF
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %63
54: ; preds = %49
%55 = load i32, i32* %10
%56 = icmp eq i32 %55, 48
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i64 0, i64 0))
br label %62
59: ; preds = %54
%60 = load i32, i32* %10
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %59, %57
br label %49
63: ; preds = %49
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.18, i64 0, i64 0))
store i32 0, i32* %1
%65 = load i8*, i8** %3
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@.str.2 = [20 x i8] c"\09got %i characters\0A\00"
@.str.3 = [15 x i8] c"\09got this: %s\0A\00"
@.str.4 = [7 x i8] c"325abc\00"
@.str.6 = [21 x i8] c"\09found '%i' in '%s'\0A\00"
@.str.7 = [11 x i8] c" -325abc\00"
@.str.10 = [21 x i8] c"\09found '%s' in '%i'\0A\00"
@.str.11 = [14 x i8] c"Good Morning!\00"
@.str.12 = [5 x i8] c"ning\00"
@.str.14 = [36 x i8] c"\09found '%s' at position %i in '%s'\0A\00"
@EOF = global i32 0
@.str.17 = [5 x i8] c"\09%c\0A\00"
@str.19 = [29 x i8] c"getline (waiting for input):\00"
@str.21 = [6 x i8] c"atoi:\00"
@str.23 = [16 x i8] c"atoi version 2:\00"
@str.25 = [6 x i8] c"itoa:\00"
@str.27 = [10 x i8] c"strindex:\00"
@str.28 = [17 x i8] c"\0A===============\00"
@str.29 = [27 x i8] c"getop (waiting for input):\00"
@str.30 = [8 x i8] c"\0A\0ADone.\00"
@str.31 = [8 x i8] c"\09number\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [100 x i8]
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.28, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.19, i64 0, i64 0))
%7 = call i32 @mgetline(i8* %4, i32 20)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.28, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.21, i64 0, i64 0))
%12 = call i32 @matoi(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.28, i64 0, i64 0))
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.23, i64 0, i64 0))
%16 = call i32 @matoi2(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.28, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.25, i64 0, i64 0))
%21 = call i32 @mitoa(i32 12345, i8* %18)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i8* %18, i32 12345)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.28, i64 0, i64 0))
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.27, i64 0, i64 0))
%25 = call i32 @strindex(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i32 %25, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.28, i64 0, i64 0))
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.29, i64 0, i64 0))
%30 = call i32 @getop(i8* %27)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %44, label %33
33: ; preds = %0, %40
%34 = phi i32 [ %41, %40 ], [ %30, %0 ]
%35 = icmp eq i32 %34, 48
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.31, i64 0, i64 0))
br label %40
38: ; preds = %33
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0), i32 %34)
br label %40
40: ; preds = %38, %36
%41 = call i32 @getop(i8* %27)
%42 = load i32, i32* @EOF
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %33
44: ; preds = %40, %0
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.30, i64 0, i64 0))
ret i32 0
}