#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 */
unsigned char atoi(unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
unsigned char *strtok(unsigned char *, char *);
int main() {
  unsigned char str[] = "00:01:02:03:04:05";
  unsigned char *pch;
  unsigned char mac[6];
  int i = 0;
  printf("Splitting string \"%s\" into tokens:\n", str);
  pch = strtok(str, ":");
  while (pch != NULL) {
    mac[i] = atoi(pch);
    pch = strtok(NULL, ":");
    i++;
  }
  for (i = 0; i < 6; i++)
    printf("%02x:", mac[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb4(%rip),%ax
mov    %ax,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cd <main+0x9d>
mov    -0x28(%rbp),%rdi
call   1050 <atoi@plt>
mov    %al,%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x2e(%rbp,%rax,1)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe84(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118d <main+0x5d>
movl   $0x0,-0x34(%rbp)
cmpl   $0x6,-0x34(%rbp)
jge    1203 <main+0xd3>
movslq -0x34(%rbp),%rax
movzbl -0x2e(%rbp,%rax,1),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d4 <main+0xa4>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movaps 0xeab(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x35,0x20(%rsp)
lea    0xeaa(%rip),%rdi
xor    %r14d,%r14d
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
mov    $0x0,%r15d
mov    $0x0,%r12d
mov    $0x0,%r13d
mov    $0x0,%ebp
mov    $0x0,%esi
test   %rax,%rax
je     1200 <main+0xc0>
lea    0xa(%rsp),%rbp
lea    0xe84(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %al,0x0(%rbp)
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    11c0 <main+0x80>
movzbl 0xa(%rsp),%esi
movzbl 0xb(%rsp),%ebp
movzbl 0xc(%rsp),%r13d
movzbl 0xd(%rsp),%r12d
movzbl 0xe(%rsp),%r15d
movzbl 0xf(%rsp),%r14d
lea    0xe2f(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.str = [18 x i8] c"00:01:02:03:04:05\00"
@.str = [36 x i8] c"Splitting string \22%s\22 into tokens:\0A\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [6 x i8] c"%02x:\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [18 x i8]
%3 = alloca i8*
%4 = alloca [6 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [18 x i8]* %2 to i8*
store i32 0, i32* %5
%7 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%10 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %3
br label %11
11: ; preds = %14, %0
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = call zeroext i8 @atoi(i8* %15)
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 %18
store i8 %16, i8* %19
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %3
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %11
23: ; preds = %11
store i32 0, i32* %5
br label %24
24: ; preds = %34, %23
%25 = load i32, i32* %5
%26 = icmp slt i32 %25, 6
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %27
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %24
37: ; preds = %24
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [18 x i8] c"00:01:02:03:04:05\00"
@.str = [36 x i8] c"Splitting string \22%s\22 into tokens:\0A\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [6 x i8] c"%02x:\00"
define i32 @main() {
%1 = alloca [18 x i8]
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %26, label %40
8: ; preds = %40
%9 = load i8, i8* %4
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 1
%11 = load i8, i8* %10
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 2
%13 = load i8, i8* %12
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 3
%15 = load i8, i8* %14
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 4
%17 = load i8, i8* %16
%18 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 5
%19 = load i8, i8* %18
%20 = zext i8 %9 to i32
%21 = zext i8 %11 to i32
%22 = zext i8 %13 to i32
%23 = zext i8 %15 to i32
%24 = zext i8 %17 to i32
%25 = zext i8 %19 to i32
br label %26
26: ; preds = %8, %0
%27 = phi i32 [ %25, %8 ], [ 0, %0 ]
%28 = phi i32 [ %24, %8 ], [ 0, %0 ]
%29 = phi i32 [ %23, %8 ], [ 0, %0 ]
%30 = phi i32 [ %22, %8 ], [ 0, %0 ]
%31 = phi i32 [ %21, %8 ], [ 0, %0 ]
%32 = phi i32 [ %20, %8 ], [ 0, %0 ]
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%39 = call i32 @putchar(i32 10)
ret i32 0
40: ; preds = %0, %40
%41 = phi i64 [ %46, %40 ], [ 0, %0 ]
%42 = phi i8* [ %45, %40 ], [ %6, %0 ]
%43 = call zeroext i8 @atoi(i8* %42)
%44 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 %41
store i8 %43, i8* %44
%45 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%46 = add nuw i64 %41, 1
%47 = icmp eq i8* %45, null
br i1 %47, label %8, label %40
}