#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*/ execv(char *, char **);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sethostname(char *, int);
int /*<<< orphan*/ system(char *);
int container_main(void *arg) {
  char **args = (char **)arg;
  printf("Container [%5d] - inside the container!\n", getpid());
  if (sethostname("container", 10)) {
    perror("sethostname");
  }
  system("mount -t proc proc /proc");
  execv(args[0], args);
  printf("Something's wrong!\n");
  return 1;
}


x86 assembly (clang, -O0):
<container_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe97(%rip),%rdi
mov    $0xa,%esi
call   1060 <sethostname@plt>
cmp    $0x0,%rax
je     11b2 <container_main+0x52>
lea    0xe86(%rip),%rdi
call   1070 <perror@plt>
lea    0xe86(%rip),%rdi
call   1040 <system@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <execv@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<container_main>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe7e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe97(%rip),%rdi
mov    $0xa,%esi
call   1070 <sethostname@plt>
test   %rax,%rax
jne    11cb <container_main+0x5b>
lea    0xe97(%rip),%rdi
call   1050 <system@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1090 <execv@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe61(%rip),%rdi
call   1080 <perror@plt>
jmp    11a1 <container_main+0x31>

LLVM IR (-O0):
@.str = [41 x i8] c"Container [%5d] - inside the container!\0A\00"
@.str.1 = [10 x i8] c"container\00"
@.str.2 = [12 x i8] c"sethostname\00"
@.str.3 = [25 x i8] c"mount -t proc proc /proc\00"
@.str.4 = [20 x i8] c"Something's wrong!\0A\00"
define i32 @container_main(i8* %0) {
%2 = alloca i8*
%3 = alloca i8**
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = bitcast i8* %4 to i8**
store i8** %5, i8*** %3
%6 = call i32 (...) @getpid()
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i64 @sethostname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 10)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = call i32 @system(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%14 = load i8**, i8*** %3
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %3
%18 = call i32 @execv(i8* %16, i8** %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [41 x i8] c"Container [%5d] - inside the container!\0A\00"
@.str.1 = [10 x i8] c"container\00"
@.str.2 = [12 x i8] c"sethostname\00"
@.str.3 = [25 x i8] c"mount -t proc proc /proc\00"
@str = [19 x i8] c"Something's wrong!\00"
define i32 @container_main(i8* %0) {
%2 = bitcast i8* %0 to i8**
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i64 @sethostname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 10)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = tail call i32 @system(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = tail call i32 @execv(i8* %11, i8** %2)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
ret i32 1
}