#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
int add_word(char *curr_word, int size_word, FILE *tempfile) {
  if (tempfile == NULL) {
    fprintf(stderr, "Invalid file\n");
    return 1;
  }
  curr_word[size_word] = '\0';
  fprintf(tempfile, "%s\n", curr_word);
  return 0;
}


x86 assembly (clang, -O0):
<add_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1152 <add_word+0x42>
mov    0x2eab(%rip),%rax
movslq (%rax),%rdi
lea    0xec1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    117b <add_word+0x6b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xea1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_word>:
push   %rbx
test   %rdx,%rdx
je     1148 <add_word+0x28>
mov    %rdi,%rax
movslq %esi,%rcx
movb   $0x0,(%rdi,%rcx,1)
lea    0xed7(%rip),%rsi
xor    %ebx,%ebx
mov    %rdx,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    116d <add_word+0x4d>
mov    0x2e91(%rip),%rax
movslq (%rax),%rcx
lea    0xea7(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"Invalid file\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @add_word(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%8 = load i32*, i32** %7
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %23
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
%20 = load i32*, i32** %7
%21 = load i8*, i8** %5
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 0, i32* %4
br label %23
23: ; preds = %15, %10
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"Invalid file\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @add_word(i8* %0, i32 %1, i32* %2) {
%4 = icmp eq i32* %2, null
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i32*
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 13, i64 1, i32* %8)
br label %14
10: ; preds = %3
%11 = sext i32 %1 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 0, i8* %12
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %10, %5
%15 = phi i32 [ 1, %5 ], [ 0, %10 ]
ret i32 %15
}