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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ has_enough_lines(size_t const, int /*<<< orphan*/ *);
int hide_byte(char const, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove(char const *);
int hide(const char *input_buf, const size_t input_buf_size,
         const char *cover_path, const char *output_path) {
  const char *ip = input_buf;
  const char *ip_end = ip + input_buf_size;
  FILE *cover_fp = NULL;
  FILE *output_fp = NULL;
  unsigned char byte = 0;
  int b = 0;
  int should_continue = 1;
  if (input_buf == NULL || cover_path == NULL || output_path == NULL) {
    return 1;
  }
  output_fp = fopen(output_path, "wb");
  if (output_fp == NULL) {
    printf("ERROR: unable to write to \"%s\".\n", output_path);
    return 1;
  }
  cover_fp = fopen(cover_path, "rb");
  if (cover_fp == NULL) {
    fclose(output_fp);
    printf("ERROR: unable to read from \"%s\".\n", cover_path);
    return 1;
  }
  if (!has_enough_lines(input_buf_size, cover_fp)) {
    printf("ERROR: the cover file must be larger.\n");
    fclose(output_fp);
    fclose(cover_fp);
    remove(output_path);
    return 1;
  }
  b = sizeof(input_buf_size) - 1;
  while (b > -1 && should_continue) {
    byte = input_buf_size >> (8 * b);
    should_continue = hide_byte(byte, cover_fp, output_fp);
    b--;
  }
  while (ip != ip_end && should_continue) {
    should_continue = hide_byte(*ip, cover_fp, output_fp);
    ip++;
  }
  if (should_continue) {
    while (hide_byte(0, cover_fp, output_fp))
      ;
  }
  fclose(output_fp);
  fclose(cover_fp);
  return (should_continue) ? 0 : 1;
}


x86 assembly (clang, -O0):
<hide>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movb   $0x0,-0x49(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x1,-0x54(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11cf <hide+0x6f>
cmpq   $0x0,-0x20(%rbp)
je     11cf <hide+0x6f>
cmpq   $0x0,-0x28(%rbp)
jne    11db <hide+0x7b>
movl   $0x1,-0x4(%rbp)
jmp    13c1 <hide+0x261>
mov    -0x28(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1218 <hide+0xb8>
mov    -0x28(%rbp),%rsi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c1 <hide+0x261>
mov    -0x20(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    125e <hide+0xfe>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rsi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c1 <hide+0x261>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <has_enough_lines@plt>
cmp    $0x0,%eax
jne    12a9 <hide+0x149>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <remove@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c1 <hide+0x261>
movl   $0x7,-0x50(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x50(%rbp)
mov    %al,-0x55(%rbp)
jle    12c9 <hide+0x169>
cmpl   $0x0,-0x54(%rbp)
setne  %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    12d9 <hide+0x179>
jmp    130f <hide+0x1af>
mov    -0x18(%rbp),%rax
mov    -0x50(%rbp),%ecx
shl    $0x3,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
movsbl %al,%edi
call   1040 <hide_byte@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x50(%rbp)
jmp    12b0 <hide+0x150>
jmp    1314 <hide+0x1b4>
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
cmp    -0x38(%rbp),%rcx
mov    %al,-0x56(%rbp)
je     1331 <hide+0x1d1>
cmpl   $0x0,-0x54(%rbp)
setne  %al
mov    %al,-0x56(%rbp)
mov    -0x56(%rbp),%al
test   $0x1,%al
jne    1341 <hide+0x1e1>
jmp    136b <hide+0x20b>
mov    -0x30(%rbp),%rax
mov    (%rax),%al
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
movsbl %al,%edi
call   1040 <hide_byte@plt>
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1314 <hide+0x1b4>
cmpl   $0x0,-0x54(%rbp)
je     139c <hide+0x23c>
jmp    137a <hide+0x21a>
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
xor    %edi,%edi
call   1040 <hide_byte@plt>
cmp    $0x0,%eax
je     1397 <hide+0x237>
jmp    137a <hide+0x21a>
jmp    139c <hide+0x23c>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x54(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hide>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
mov    %rdi,(%rsp)
test   %rdi,%rdi
je     12e4 <hide+0x174>
mov    %rdx,%r13
test   %rdx,%rdx
je     12e4 <hide+0x174>
mov    %rcx,%rbp
test   %rcx,%rcx
je     12e4 <hide+0x174>
mov    %rsi,%r15
lea    0xe51(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1299 <hide+0x129>
mov    %rax,%r14
lea    0xe5a(%rip),%rsi
mov    %r13,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a5 <hide+0x135>
mov    %rax,%r12
mov    %r15,%rdi
mov    %rax,%rsi
call   1090 <has_enough_lines@plt>
test   %eax,%eax
je     12c0 <hide+0x150>
mov    $0x38,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rax
mov    %ebp,%ecx
shr    %cl,%rax
movsbl %al,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <hide_byte@plt>
test   %eax,%eax
setne  %bl
test   %rbp,%rbp
je     1228 <hide+0xb8>
add    $0xfffffffffffffff8,%rbp
test   %eax,%eax
jne    1200 <hide+0x90>
test   %r15,%r15
mov    (%rsp),%r13
je     1263 <hide+0xf3>
test   %eax,%eax
je     1263 <hide+0xf3>
add    $0xffffffffffffffff,%r15
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%r13,%rbp,1),%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <hide_byte@plt>
test   %eax,%eax
setne  %bl
cmp    %rbp,%r15
je     1263 <hide+0xf3>
add    $0x1,%rbp
test   %eax,%eax
jne    1240 <hide+0xd0>
test   %bl,%bl
je     1281 <hide+0x111>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <hide_byte@plt>
test   %eax,%eax
jne    1270 <hide+0x100>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
xor    $0x1,%bl
movzbl %bl,%ebx
jmp    12e4 <hide+0x174>
lea    0xd63(%rip),%rdi
mov    %rbp,%rsi
jmp    12b7 <hide+0x147>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xd73(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12e4 <hide+0x174>
lea    0xd82(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %rbp,%rdi
call   1030 <remove@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [33 x i8] c"ERROR: unable to write to \22%s\22.\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [34 x i8] c"ERROR: unable to read from \22%s\22.\0A\00"
@.str.4 = [39 x i8] c"ERROR: the cover file must be larger.\0A\00"
define i32 @hide(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%17 = load i8*, i8** %6
store i8* %17, i8** %10
%18 = load i8*, i8** %10
%19 = load i64, i64* %7
%20 = getelementptr inbounds i8, i8* %18, i64 %19
store i8* %20, i8** %11
store i32* null, i32** %12
store i32* null, i32** %13
store i8 0, i8* %14
store i32 0, i32* %15
store i32 1, i32* %16
%21 = load i8*, i8** %6
%22 = icmp eq i8* %21, null
br i1 %22, label %29, label %23
23: ; preds = %4
%24 = load i8*, i8** %8
%25 = icmp eq i8* %24, null
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i8*, i8** %9
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %26, %23, %4
store i32 1, i32* %5
br label %121
30: ; preds = %26
%31 = load i8*, i8** %9
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %32, i32** %13
%33 = load i32*, i32** %13
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i8*, i8** %9
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %36)
store i32 1, i32* %5
br label %121
38: ; preds = %30
%39 = load i8*, i8** %8
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %40, i32** %12
%41 = load i32*, i32** %12
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = load i32*, i32** %13
%45 = call i32 @fclose(i32* %44)
%46 = load i8*, i8** %8
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %46)
store i32 1, i32* %5
br label %121
48: ; preds = %38
%49 = load i64, i64* %7
%50 = load i32*, i32** %12
%51 = call i32 @has_enough_lines(i64 %49, i32* %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %61, label %53
53: ; preds = %48
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%55 = load i32*, i32** %13
%56 = call i32 @fclose(i32* %55)
%57 = load i32*, i32** %12
%58 = call i32 @fclose(i32* %57)
%59 = load i8*, i8** %9
%60 = call i32 @remove(i8* %59)
store i32 1, i32* %5
br label %121
61: ; preds = %48
store i32 7, i32* %15
br label %62
62: ; preds = %70, %61
%63 = load i32, i32* %15
%64 = icmp sgt i32 %63, -1
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = load i32, i32* %16
%67 = icmp ne i32 %66, 0
br label %68
68: ; preds = %65, %62
%69 = phi i1 [ false, %62 ], [ %67, %65 ]
br i1 %69, label %70, label %83
70: ; preds = %68
%71 = load i64, i64* %7
%72 = load i32, i32* %15
%73 = mul nsw i32 8, %72
%74 = zext i32 %73 to i64
%75 = lshr i64 %71, %74
%76 = trunc i64 %75 to i8
store i8 %76, i8* %14
%77 = load i8, i8* %14
%78 = load i32*, i32** %12
%79 = load i32*, i32** %13
%80 = call i32 @hide_byte(i8 signext %77, i32* %78, i32* %79)
store i32 %80, i32* %16
%81 = load i32, i32* %15
%82 = add nsw i32 %81, -1
store i32 %82, i32* %15
br label %62
83: ; preds = %68
br label %84
84: ; preds = %93, %83
%85 = load i8*, i8** %10
%86 = load i8*, i8** %11
%87 = icmp ne i8* %85, %86
br i1 %87, label %88, label %91
88: ; preds = %84
%89 = load i32, i32* %16
%90 = icmp ne i32 %89, 0
br label %91
91: ; preds = %88, %84
%92 = phi i1 [ false, %84 ], [ %90, %88 ]
br i1 %92, label %93, label %101
93: ; preds = %91
%94 = load i8*, i8** %10
%95 = load i8, i8* %94
%96 = load i32*, i32** %12
%97 = load i32*, i32** %13
%98 = call i32 @hide_byte(i8 signext %95, i32* %96, i32* %97)
store i32 %98, i32* %16
%99 = load i8*, i8** %10
%100 = getelementptr inbounds i8, i8* %99, i32 1
store i8* %100, i8** %10
br label %84
101: ; preds = %91
%102 = load i32, i32* %16
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %112
104: ; preds = %101
br label %105
105: ; preds = %110, %104
%106 = load i32*, i32** %12
%107 = load i32*, i32** %13
%108 = call i32 @hide_byte(i8 signext 0, i32* %106, i32* %107)
%109 = icmp ne i32 %108, 0
br i1 %109, label %110, label %111
110: ; preds = %105
br label %105
111: ; preds = %105
br label %112
112: ; preds = %111, %101
%113 = load i32*, i32** %13
%114 = call i32 @fclose(i32* %113)
%115 = load i32*, i32** %12
%116 = call i32 @fclose(i32* %115)
%117 = load i32, i32* %16
%118 = icmp ne i32 %117, 0
%119 = zext i1 %118 to i64
%120 = select i1 %118, i32 0, i32 1
store i32 %120, i32* %5
br label %121
121: ; preds = %112, %53, %43, %35, %29
%122 = load i32, i32* %5
ret i32 %122
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [33 x i8] c"ERROR: unable to write to \22%s\22.\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [34 x i8] c"ERROR: unable to read from \22%s\22.\0A\00"
@str = [38 x i8] c"ERROR: the cover file must be larger.\00"
define i32 @hide(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = getelementptr inbounds i8, i8* %0, i64 %1
%6 = icmp eq i8* %0, null
%7 = icmp eq i8* %2, null
%8 = or i1 %6, %7
%9 = icmp eq i8* %3, null
%10 = or i1 %8, %9
br i1 %10, label %61, label %11
11: ; preds = %4
%12 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %61
16: ; preds = %11
%17 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @fclose(i32* %12)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %61
22: ; preds = %16
%23 = tail call i32 @has_enough_lines(i64 %1, i32* %17)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @fclose(i32* %12)
%28 = tail call i32 @fclose(i32* %17)
%29 = tail call i32 @remove(i8* %3)
br label %61
30: ; preds = %33
%31 = icmp ne i64 %1, 0
%32 = select i1 %31, i1 %41, i1 false
br i1 %32, label %43, label %51
33: ; preds = %22, %33
%34 = phi i64 [ %39, %33 ], [ 7, %22 ]
%35 = shl nsw i64 %34, 3
%36 = lshr i64 %1, %35
%37 = trunc i64 %36 to i8
%38 = tail call i32 @hide_byte(i8 signext %37, i32* %17, i32* %12)
%39 = add nsw i64 %34, -1
%40 = icmp ne i64 %34, 0
%41 = icmp ne i32 %38, 0
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %33, label %30
43: ; preds = %30, %43
%44 = phi i8* [ %47, %43 ], [ %0, %30 ]
%45 = load i8, i8* %44
%46 = tail call i32 @hide_byte(i8 signext %45, i32* %17, i32* %12)
%47 = getelementptr inbounds i8, i8* %44, i64 1
%48 = icmp ne i8* %47, %5
%49 = icmp ne i32 %46, 0
%50 = select i1 %48, i1 %49, i1 false
br i1 %50, label %43, label %51
51: ; preds = %43, %30
%52 = phi i1 [ %41, %30 ], [ %49, %43 ]
br i1 %52, label %53, label %56
53: ; preds = %51, %53
%54 = tail call i32 @hide_byte(i8 signext 0, i32* %17, i32* %12)
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %53
56: ; preds = %53, %51
%57 = tail call i32 @fclose(i32* %12)
%58 = tail call i32 @fclose(i32* %17)
%59 = xor i1 %52, true
%60 = zext i1 %59 to i32
br label %61
61: ; preds = %4, %56, %25, %19, %14
%62 = phi i32 [ 1, %14 ], [ 1, %19 ], [ %60, %56 ], [ 1, %25 ], [ 1, %4 ]
ret i32 %62
}