#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*/ imaxabs(int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strtoimax(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ test_strsep(char **, char *, int);
char *xstrdup(char *);
int main(void) {
  char *s1 = xstrdup("hello world");
  test_strsep(&s1, " ", true);
  char s2[] = "stack allocated";
  char *p2 = s2;
  test_strsep(&p2, " ", false);
  char *s3 = xstrdup("1,2,3,4,5,6,7,8,9,10");
  test_strsep(&s3, ",", true);
  printf("%jd\n", strtoimax("1023", NULL, 0));
  printf("%jd\n", strtoimax("0x24", NULL, 0));
  printf("%jd\n", strtoimax("101", NULL, 2));
  printf("%jd\n", imaxabs(-20));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
mov    $0x1,%edx
call   1070 <test_strsep@plt>
mov    0xeb5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb2(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
lea    0xe5f(%rip),%rsi
xor    %edx,%edx
call   1070 <test_strsep@plt>
lea    0xe53(%rip),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe54(%rip),%rsi
mov    $0x1,%edx
call   1070 <test_strsep@plt>
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <strtoimax@plt>
mov    %eax,%esi
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <strtoimax@plt>
mov    %eax,%esi
lea    0xe11(%rip),%rdi
call   1040 <printf@plt>
lea    0xe14(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x2,%edx
call   1030 <strtoimax@plt>
mov    %eax,%esi
lea    0xdee(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffec,%edi
call   1060 <imaxabs@plt>
mov    %eax,%esi
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xea4(%rip),%rdi
call   1050 <xstrdup@plt>
mov    %rax,0x18(%rsp)
lea    0xe9f(%rip),%rbx
lea    0x18(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <test_strsep@plt>
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <test_strsep@plt>
lea    0xe63(%rip),%rdi
call   1050 <xstrdup@plt>
mov    %rax,0x8(%rsp)
lea    0xe67(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    $0x1,%edx
call   1070 <test_strsep@plt>
lea    0xe58(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <strtoimax@plt>
lea    0xe43(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xe3c(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <strtoimax@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xe27(%rip),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1030 <strtoimax@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0xffffffec,%edi
call   1060 <imaxabs@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [2 x i8] c" \00"
@__const.main.s2 = [16 x i8] c"stack allocated\00"
@.str.2 = [21 x i8] c"1,2,3,4,5,6,7,8,9,10\00"
@.str.3 = [2 x i8] c",\00"
@.str.4 = [5 x i8] c"%jd\0A\00"
@.str.5 = [5 x i8] c"1023\00"
@.str.6 = [5 x i8] c"0x24\00"
@.str.7 = [4 x i8] c"101\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [16 x i8]
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i8* @xstrdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %2
%7 = call i32 @test_strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%8 = bitcast [16 x i8]* %3 to i8*
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
store i8* %9, i8** %4
%10 = call i32 @test_strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 0)
%11 = call i8* @xstrdup(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i8* %11, i8** %5
%12 = call i32 @test_strsep(i8** %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%13 = call i32 @strtoimax(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32* null, i32 0)
%14 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%15 = call i32 @strtoimax(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32* null, i32 0)
%16 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %15)
%17 = call i32 @strtoimax(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32* null, i32 2)
%18 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = call i32 @imaxabs(i32 -20)
%20 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [2 x i8] c" \00"
@__const.main.s2 = [16 x i8] c"stack allocated\00"
@.str.2 = [21 x i8] c"1,2,3,4,5,6,7,8,9,10\00"
@.str.3 = [2 x i8] c",\00"
@.str.4 = [5 x i8] c"%jd\0A\00"
@.str.5 = [5 x i8] c"1023\00"
@.str.6 = [5 x i8] c"0x24\00"
@.str.7 = [4 x i8] c"101\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca [16 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %1 to i8*
%6 = tail call i8* @xstrdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %1
%7 = call i32 @test_strsep(i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%9 = bitcast i8** %3 to i8*
store i8* %8, i8** %3
%10 = call i32 @test_strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 0)
%11 = bitcast i8** %4 to i8*
%12 = call i8* @xstrdup(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i8* %12, i8** %4
%13 = call i32 @test_strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%14 = call i32 @strtoimax(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32* null, i32 0)
%15 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = call i32 @strtoimax(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32* null, i32 0)
%17 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = call i32 @strtoimax(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32* null, i32 2)
%19 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = call i32 @imaxabs(i32 -20)
%21 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %20)
ret i32 0
}