#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*/ uid_t;
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ execle(char *, char *, char *, int /*<<< orphan*/ *,
                          char **);
int /*<<< orphan*/ free(char *);
int get_logdir_from_config(char **, char *);
int /*<<< orphan*/ init_blocked_signals(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ priv_mode(int /*<<< orphan*/, int /*<<< orphan*/ *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ unpriv_mode(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int control_tsung(char *pass_str, char *prefix) {
  sigset_t signals_to_block;
  sigset_t normalsignalset;
  char *environ[] = {NULL, NULL};
  uid_t euid;
  char *log_directory;
  int logdir_size;
  unpriv_mode(&euid, NULL);
  init_blocked_signals(&signals_to_block);
  logdir_size = get_logdir_from_config(&log_directory, prefix);
  environ[0] = (char *)malloc(sizeof(char) * (logdir_size + 5));
  environ[0][0] = '\0';
  strncat(environ[0], "HOME=", 5);
  strncat(environ[0], log_directory, logdir_size);
  priv_mode(euid, &signals_to_block, &normalsignalset);
  execle("/opt/tsung/bin/tsung", "tsung", pass_str, NULL, environ);
  unpriv_mode(&euid, &normalsignalset);
  free(log_directory);
  return 0;
}


x86 assembly (clang, -O0):
<control_tsung>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x34(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <unpriv_mode@plt>
lea    -0x14(%rbp),%rdi
call   1090 <init_blocked_signals@plt>
mov    -0x10(%rbp),%rsi
lea    -0x40(%rbp),%rdi
call   1040 <get_logdir_from_config@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
add    $0x5,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
lea    0xe01(%rip),%rsi
mov    $0x5,%edx
call   1060 <strncat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1060 <strncat@plt>
mov    -0x34(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <priv_mode@plt>
mov    -0x8(%rbp),%rdx
lea    -0x30(%rbp),%r8
lea    0xdce(%rip),%rdi
lea    0xdd6(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   10b0 <execle@plt>
lea    -0x34(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <unpriv_mode@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<control_tsung>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x4(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <unpriv_mode@plt>
lea    0x2c(%rsp),%r12
mov    %r12,%rdi
call   1080 <init_blocked_signals@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <get_logdir_from_config@plt>
mov    %eax,%r13d
lea    0x5(%r13),%edi
call   1070 <malloc@plt>
mov    %rax,0x10(%rsp)
movb   $0x0,(%rax)
mov    0x10(%rsp),%rbx
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1050 <strncat@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %r13d,%edx
call   1050 <strncat@plt>
mov    0x4(%rsp),%edi
lea    0x28(%rsp),%rbx
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <priv_mode@plt>
lea    0xdea(%rip),%rdi
lea    0xdf2(%rip),%rsi
lea    0x10(%rsp),%r8
mov    %r15,%rdx
xor    %ecx,%ecx
call   10a0 <execle@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <unpriv_mode@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"HOME=\00"
@.str.1 = [21 x i8] c"/opt/tsung/bin/tsung\00"
@.str.2 = [6 x i8] c"tsung\00"
define i32 @control_tsung(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i8*]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = bitcast [2 x i8*]* %7 to i8*
%12 = call i32 @unpriv_mode(i32* %8, i32* null)
%13 = call i32 @init_blocked_signals(i32* %5)
%14 = load i8*, i8** %4
%15 = call i32 @get_logdir_from_config(i8** %9, i8* %14)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = add nsw i32 %16, 5
%18 = sext i32 %17 to i64
%19 = mul i64 1, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
store i8* %22, i8** %23
%24 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 0, i8* %26
%27 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @strncat(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%30 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%31 = load i8*, i8** %30
%32 = load i8*, i8** %9
%33 = load i32, i32* %10
%34 = call i32 @strncat(i8* %31, i8* %32, i32 %33)
%35 = load i32, i32* %8
%36 = call i32 @priv_mode(i32 %35, i32* %5, i32* %6)
%37 = load i8*, i8** %3
%38 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%39 = call i32 @execle(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %37, i32* null, i8** %38)
%40 = call i32 @unpriv_mode(i32* %8, i32* %6)
%41 = load i8*, i8** %9
%42 = call i32 @free(i8* %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"HOME=\00"
@.str.1 = [21 x i8] c"/opt/tsung/bin/tsung\00"
@.str.2 = [6 x i8] c"tsung\00"
define i32 @control_tsung(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i8*]
%6 = alloca i32
%7 = alloca i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast [2 x i8*]* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i8** %7 to i8*
%13 = call i32 @unpriv_mode(i32* %6, i32* null)
%14 = call i32 @init_blocked_signals(i32* %3)
%15 = call i32 @get_logdir_from_config(i8** %7, i8* %1)
%16 = add nsw i32 %15, 5
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
%19 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
store i8* %18, i8** %19
store i8 0, i8* %18
%20 = load i8*, i8** %19
%21 = call i32 @strncat(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%22 = load i8*, i8** %7
%23 = call i32 @strncat(i8* %20, i8* %22, i32 %15)
%24 = load i32, i32* %6
%25 = call i32 @priv_mode(i32 %24, i32* %3, i32* %4)
%26 = call i32 @execle(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32* null, i8** %19)
%27 = call i32 @unpriv_mode(i32* %6, i32* %4)
%28 = load i8*, i8** %7
%29 = call i32 @free(i8* %28)
ret i32 0
}