#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 atoi(char *);
int /*<<< orphan*/ ofree(char *);
char *ostrdup(char *);
char *strtok(char *, char *);
int get_xdim(char *str) {
  int ret = 0;
  char *dup;
  char *tok;
  dup = ostrdup(str);
  strtok(dup, " ");
  strtok(NULL, " ");
  tok = strtok(NULL, " ");
  if (tok != NULL) {
    ret = atoi(tok);
  }
  ofree(dup);
  return (ret);
}


x86 assembly (clang, -O0):
<get_xdim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ostrdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <strtok@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe85(%rip),%rsi
call   1050 <strtok@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe75(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ab <get_xdim+0x6b>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ofree@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_xdim>:
push   %r15
push   %r14
push   %rbx
call   1030 <ostrdup@plt>
mov    %rax,%r14
lea    0xeac(%rip),%r15
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strtok@plt>
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     1184 <get_xdim+0x44>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <ofree@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i32 @get_xdim(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
%7 = call i8* @ostrdup(i8* %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i8*, i8** %5
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %3
br label %17
17: ; preds = %14, %1
%18 = load i8*, i8** %4
%19 = call i32 @ofree(i8* %18)
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i32 @get_xdim(i8* %0) {
%2 = tail call i8* @ostrdup(i8* %0)
%3 = tail call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @atoi(i8* %5)
br label %9
9: ; preds = %7, %1
%10 = phi i32 [ %8, %7 ], [ 0, %1 ]
%11 = tail call i32 @ofree(i8* %2)
ret i32 %10
}