#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 */

/* Variables and functions */
int /*<<< orphan*/ do_it(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *);
char *read_file(char *);
int /*<<< orphan*/ write_file(char *, char *);
int main(int argc, char **argv) {
  char *buf;
  if (argc < 3) {
    printf("usage: wrapns [file] [namespace]\n\n");
    return 1;
  }
  buf = read_file(argv[1]);
  do_it(buf, argv[2]);
  write_file(argv[1], buf);
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cb <main+0x7b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <read_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <do_it@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <write_file@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     116c <main+0x1c>
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    119d <main+0x4d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <read_file@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rsi
mov    %rax,%rdi
call   1070 <do_it@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1050 <write_file@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c"usage: wrapns [file] [namespace]\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %28
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i8* @read_file(i8* %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @do_it(i8* %16, i8* %19)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i8*, i8** %6
%25 = call i32 @write_file(i8* %23, i8* %24)
%26 = load i8*, i8** %6
%27 = call i32 @free(i8* %26)
store i32 0, i32* %3
br label %28
28: ; preds = %11, %9
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@str = [34 x i8] c"usage: wrapns [file] [namespace]\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %16
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i8* @read_file(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @do_it(i8* %9, i8* %11)
%13 = load i8*, i8** %7
%14 = tail call i32 @write_file(i8* %13, i8* %9)
%15 = tail call i32 @free(i8* %9)
br label %16
16: ; preds = %6, %4
%17 = phi i32 [ 1, %4 ], [ 0, %6 ]
ret i32 %17
}