#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*/ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int copy_word_from_file(FILE *fp, char **new_word) {
  char word[500];
  fscanf(fp, "%[^,]", word);
  *new_word = malloc(strlen(word) + 1);
  if (!*new_word)
    return 0;
  strcpy(*new_word, word);
  fgetc(fp);
  return 1;
}


x86 assembly (clang, -O0):
<copy_word_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x210(%rbp),%rdx
lea    0xe8b(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b6 <copy_word_from_file+0x66>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <copy_word_from_file+0x89>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0x210(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_word_from_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe97(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11a7 <copy_word_from_file+0x57>
mov    %rsp,%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    $0x1,%eax
jmp    11a9 <copy_word_from_file+0x59>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%[^,]\00"
define i32 @copy_word_from_file(i32* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8**
%6 = alloca [500 x i8]
store i32* %0, i32** %4
store i8** %1, i8*** %5
%7 = load i32*, i32** %4
%8 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%9 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 1
%13 = call i8* @malloc(i64 %12)
%14 = load i8**, i8*** %5
store i8* %13, i8** %14
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %2
store i32 0, i32* %3
br label %26
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i32*, i32** %4
%25 = call i32 @fgetc(i32* %24)
store i32 1, i32* %3
br label %26
26: ; preds = %19, %18
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [6 x i8] c"%[^,]\00"
define i32 @copy_word_from_file(i32* nocapture %0, i8** nocapture writeonly %1) {
%3 = alloca [500 x i8]
%4 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%5 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i64 @strlen(i8* %4)
%7 = add nsw i64 %6, 1
%8 = call i8* @malloc(i64 %7)
store i8* %8, i8** %1
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = call i32 @strcpy(i8* %8, i8* %4)
%12 = call i32 @fgetc(i32* %0)
br label %13
13: ; preds = %2, %10
%14 = phi i32 [ 1, %10 ], [ 0, %2 ]
ret i32 %14
}