#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 INT_MIN;
int /*<<< orphan*/ _getline_ptr(char *, int);
int /*<<< orphan*/ itoa_alt_ptr(int, char *);
int /*<<< orphan*/ itoa_recursive_ptr(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int strindex_ptr(char *, char *);
int main(void) {
  char line[1000] = {0};
  char string1[100] = {0};
  char string2[100] = {0};
  _getline_ptr(line, 1000);
  printf("getline_ptr() result is:\n%s\n", line);
  itoa_alt_ptr(INT_MIN, string1);
  printf("itoa_alt_ptr() result for \'-2147483648\' (INT_MIN) is %s\n",
         string1);
  itoa_recursive_ptr(INT_MIN, string2);
  printf("itoa_recursive_ptr() result for \'-2147483648\' (INT_MIN) is %s\n",
         string2);
  printf("atoi_ptr() result for \'-2147483648\' (INT_MIN) is %d\n", INT_MIN);
  printf("strindex_ptr() result for \'world\' in \'hello world\' is %d\n",
         strindex_ptr("hello world", "world") + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3f0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1040 <memset@plt>
lea    -0x460(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
lea    -0x4d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
lea    -0x3f0(%rbp),%rdi
mov    $0x3e8,%esi
call   1080 <_getline_ptr@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    -0x460(%rbp),%rsi
call   1060 <itoa_alt_ptr@plt>
lea    -0x460(%rbp),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    -0x4d0(%rbp),%rsi
call   1050 <itoa_recursive_ptr@plt>
lea    -0x4d0(%rbp),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1070 <strindex_ptr@plt>
mov    %eax,%esi
add    $0x1,%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x4d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x4c8,%rsp
lea    0xe0(%rsp),%rbx
mov    $0x3e8,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movl   $0x0,0xd0(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1080 <_getline_ptr@plt>
lea    0xe0b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2de2(%rip),%r14
mov    (%r14),%edi
lea    0x70(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <itoa_alt_ptr@plt>
lea    0xe00(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r14),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <itoa_recursive_ptr@plt>
lea    0xe1a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r14),%esi
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea6(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1070 <strindex_ptr@plt>
lea    0x1(%rax),%esi
lea    0xe56(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x4c8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [29 x i8] c"getline_ptr() result is:\0A%s\0A\00"
@INT_MIN = global i32 0
@.str.1 = [57 x i8] c"itoa_alt_ptr() result for '-2147483648' (INT_MIN) is %s\0A\00"
@.str.2 = [63 x i8] c"itoa_recursive_ptr() result for '-2147483648' (INT_MIN) is %s\0A\00"
@.str.3 = [53 x i8] c"atoi_ptr() result for '-2147483648' (INT_MIN) is %d\0A\00"
@.str.4 = [58 x i8] c"strindex_ptr() result for 'world' in 'hello world' is %d\0A\00"
@.str.5 = [12 x i8] c"hello world\00"
@.str.6 = [6 x i8] c"world\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = bitcast [1000 x i8]* %2 to i8*
%6 = bitcast [100 x i8]* %3 to i8*
%7 = bitcast [100 x i8]* %4 to i8*
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%9 = call i32 @_getline_ptr(i8* %8, i32 1000)
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @INT_MIN
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%14 = call i32 @itoa_alt_ptr(i32 %12, i8* %13)
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @INT_MIN
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%19 = call i32 @itoa_recursive_ptr(i32 %17, i8* %18)
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @INT_MIN
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = call i32 @strindex_ptr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%25 = add nsw i32 %24, 1
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"getline_ptr() result is:\0A%s\0A\00"
@INT_MIN = global i32 0
@.str.1 = [57 x i8] c"itoa_alt_ptr() result for '-2147483648' (INT_MIN) is %s\0A\00"
@.str.2 = [63 x i8] c"itoa_recursive_ptr() result for '-2147483648' (INT_MIN) is %s\0A\00"
@.str.3 = [53 x i8] c"atoi_ptr() result for '-2147483648' (INT_MIN) is %d\0A\00"
@.str.4 = [58 x i8] c"strindex_ptr() result for 'world' in 'hello world' is %d\0A\00"
@.str.5 = [12 x i8] c"hello world\00"
@.str.6 = [6 x i8] c"world\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = call i32 @_getline_ptr(i8* %4, i32 1000)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %4)
%9 = load i32, i32* @INT_MIN
%10 = call i32 @itoa_alt_ptr(i32 %9, i8* %5)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%12 = load i32, i32* @INT_MIN
%13 = call i32 @itoa_recursive_ptr(i32 %12, i8* %6)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%15 = load i32, i32* @INT_MIN
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = call i32 @strindex_ptr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%18 = add nsw i32 %17, 1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i32 %18)
ret i32 0
}