#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 */
char *malloc(scalar_t__);
int /*<<< orphan*/ next_line_str(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int next_line_str_alloc(FILE *f, char *tag, char **out) {
  char str[256];
  if (!next_line_str(f, tag, str))
    goto error;
  *out = malloc(strlen(str) + 1);
  strcpy(*out, str);
  return 1;
error:
  return 0;
}


x86 assembly (clang, -O0):
<next_line_str_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x120(%rbp),%rdx
call   1050 <next_line_str@plt>
cmp    $0x0,%eax
jne    1179 <next_line_str_alloc+0x39>
jmp    11ba <next_line_str_alloc+0x7a>
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    -0x120(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c1 <next_line_str_alloc+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_line_str_alloc>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%rbx
mov    %rsp,%rdx
call   1050 <next_line_str@plt>
test   %eax,%eax
je     1182 <next_line_str_alloc+0x42>
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%eax
jmp    1184 <next_line_str_alloc+0x44>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @next_line_str_alloc(i32* %0, i8* %1, i8** nocapture writeonly %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @next_line_str(i32* %0, i8* %1, i8* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = call i64 @strlen(i8* %5)
%10 = add nsw i64 %9, 1
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %2
%12 = call i32 @strcpy(i8* %11, i8* %5)
br label %13
13: ; preds = %3, %8
%14 = phi i32 [ 1, %8 ], [ 0, %3 ]
ret i32 %14
}