#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 /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ sethostname(char *, int);
int container_main(void *arg) {
  char **args = (char **)arg;
  printf("Container - inside the container!\n");
  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)
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
mov    $0xa,%esi
call   1040 <sethostname@plt>
cmp    $0x0,%rax
je     1187 <container_main+0x47>
lea    0xeab(%rip),%rdi
call   1050 <perror@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execv@plt>
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<container_main>:
push   %rbx
mov    %rdi,%rbx
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
lea    0xea9(%rip),%rdi
mov    $0xa,%esi
call   1040 <sethostname@plt>
test   %rax,%rax
jne    1184 <container_main+0x44>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1060 <execv@plt>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe7f(%rip),%rdi
call   1050 <perror@plt>
jmp    1166 <container_main+0x26>

LLVM IR (-O0):
@.str = [35 x i8] c"Container - 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 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%7 = call i64 @sethostname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 10)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load i8**, i8*** %3
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = load i8**, i8*** %3
%16 = call i32 @execv(i8* %14, i8** %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
ret i32 1
}

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