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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fread(char *, int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *);
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int copy_comment(FILE *ifp, FILE *ofp, uint32_t num_bytes_comment) {
  char *buf;
  if (num_bytes_comment == 0)
    return 1;
  buf = malloc(num_bytes_comment);
  if (!buf) {
    fprintf(stderr, "malloc failed\n");
    return 0;
  }
  if (!fread(buf, num_bytes_comment, 1, ifp)) {
    fprintf(stderr, "failed to read comment\n");
    free(buf);
    return 0;
  }
  if (!fwrite(buf, num_bytes_comment, 1, ofp)) {
    fprintf(stderr, "failed to write comment\n");
    free(buf);
    return 0;
  }
  free(buf);
  return 1;
}


x86 assembly (clang, -O0):
<copy_comment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1179 <copy_comment+0x29>
movl   $0x1,-0x4(%rbp)
jmp    1251 <copy_comment+0x101>
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b1 <copy_comment+0x61>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1251 <copy_comment+0x101>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%eax
jne    11f9 <copy_comment+0xa9>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1251 <copy_comment+0x101>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x0,%eax
jne    1241 <copy_comment+0xf1>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1251 <copy_comment+0x101>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_comment>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
je     11ad <copy_comment+0x5d>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b4 <copy_comment+0x64>
mov    %rax,%r15
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     11cb <copy_comment+0x7b>
mov    $0x1,%ebx
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
test   %eax,%eax
je     11dd <copy_comment+0x8d>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11fc <copy_comment+0xac>
mov    $0x1,%ebx
jmp    11fc <copy_comment+0xac>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11fa <copy_comment+0xaa>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
jmp    11ed <copy_comment+0x9d>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
@.str.1 = [24 x i8] c"failed to read comment\0A\00"
@.str.2 = [25 x i8] c"failed to write comment\0A\00"
define i32 @copy_comment(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 1, i32* %4
br label %45
12: ; preds = %3
%13 = load i32, i32* %7
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %45
20: ; preds = %12
%21 = load i8*, i8** %8
%22 = load i32, i32* %7
%23 = load i32*, i32** %5
%24 = call i32 @fread(i8* %21, i32 %22, i32 1, i32* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%29 = load i8*, i8** %8
%30 = call i32 @free(i8* %29)
store i32 0, i32* %4
br label %45
31: ; preds = %20
%32 = load i8*, i8** %8
%33 = load i32, i32* %7
%34 = load i32*, i32** %6
%35 = call i32 @fwrite(i8* %32, i32 %33, i32 1, i32* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%40 = load i8*, i8** %8
%41 = call i32 @free(i8* %40)
store i32 0, i32* %4
br label %45
42: ; preds = %31
%43 = load i8*, i8** %8
%44 = call i32 @free(i8* %43)
store i32 1, i32* %4
br label %45
45: ; preds = %42, %37, %26, %17, %11
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
@.str.1 = [24 x i8] c"failed to read comment\0A\00"
@.str.2 = [25 x i8] c"failed to write comment\0A\00"
define i32 @copy_comment(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %27, label %5
5: ; preds = %3
%6 = tail call i8* @malloc(i32 %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %27
11: ; preds = %5
%12 = tail call i32 @fread(i8* %6, i32 %2, i32 1, i32* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @free(i8* %6)
br label %27
18: ; preds = %11
%19 = tail call i32 @fwrite(i8* %6, i32 %2, i32 1, i32* %1)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @free(i8* %6)
br label %27
25: ; preds = %18
%26 = tail call i32 @free(i8* %6)
br label %27
27: ; preds = %3, %25, %21, %14, %8
%28 = phi i32 [ 1, %25 ], [ 0, %21 ], [ 0, %14 ], [ 0, %8 ], [ 1, %3 ]
ret i32 %28
}