#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*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int strlen(char const *);
int system(char *);
int grep_for_word(const char *word) {
  size_t length;
  char *buffer;
  int exit_code;
  length = strlen("grep -x ") + strlen(word) + strlen(" /usr/dict/words") + 1;
  buffer = (char *)malloc(length);
  sprintf(buffer, "grep -x %s /usr/dict/words", word);
  exit_code = system(buffer);
  free(buffer);
  return exit_code == 0;
}


x86 assembly (clang, -O0):
<grep_for_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
lea    0xe8e(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grep_for_word>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea2(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xe9d(%rip),%rdi
call   1040 <strlen@plt>
add    %ebp,%ebx
add    %ebx,%eax
add    $0x1,%eax
movslq %eax,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe75(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"grep -x \00"
@.str.1 = [17 x i8] c" /usr/dict/words\00"
@.str.2 = [27 x i8] c"grep -x %s /usr/dict/words\00"
define i32 @grep_for_word(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %6, %8
%10 = call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%11 = add nsw i32 %9, %10
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
store i64 %13, i64* %3
%14 = load i64, i64* %3
%15 = call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = load i8*, i8** %2
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %4
%21 = call i32 @system(i8* %20)
store i32 %21, i32* %5
%22 = load i8*, i8** %4
%23 = call i32 @free(i8* %22)
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
ret i32 %26
}

LLVM IR (-O2):
@.str = [9 x i8] c"grep -x \00"
@.str.1 = [17 x i8] c" /usr/dict/words\00"
@.str.2 = [27 x i8] c"grep -x %s /usr/dict/words\00"
define i32 @grep_for_word(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%5 = add i32 %2, 1
%6 = add i32 %5, %3
%7 = add i32 %6, %4
%8 = sext i32 %7 to i64
%9 = tail call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%12 = tail call i32 @system(i8* %10)
%13 = tail call i32 @free(i8* %10)
%14 = icmp eq i32 %12, 0
%15 = zext i1 %14 to i32
ret i32 %15
}