#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 container_main(void *arg) {
  char **args = (char **)arg;
  printf("Container [%5d] - inside the container!\n", getpid());
  if (sethostname("container", 10)) {
    perror("sethostname");
  }
  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    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
mov    $0xa,%esi
call   1050 <sethostname@plt>
cmp    $0x0,%rax
je     11a2 <container_main+0x52>
lea    0xe96(%rip),%rdi
call   1060 <perror@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execv@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <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    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea7(%rip),%rdi
mov    $0xa,%esi
call   1060 <sethostname@plt>
test   %rax,%rax
jne    11af <container_main+0x4f>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1080 <execv@plt>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe7d(%rip),%rdi
call   1070 <perror@plt>
jmp    1191 <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 = [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 = load i8**, i8*** %3
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %3
%17 = call i32 @execv(i8* %15, i8** %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, 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 = [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 = load i8*, i8** %2
%11 = tail call i32 @execv(i8* %10, i8** %2)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
ret i32 1
}