#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 execlp(char *, char *, char *, ...);
int /*<<< orphan*/ mydm_print(char *, char *);
scalar_t__ switch_user(char *);
int exec_try_login_user(char *username, char *file, int no_system_su) {
  if (username) {
    if (no_system_su) {
      if (switch_user(username) < 0) {
        mydm_print("Can not login user '%s'\n", username);
        return -1;
      }
      return execlp(file, file, NULL);
    } else {
      return execlp("su", "su", "-", username, "-c", file, NULL);
    }
  } else {
    return execlp(file, file, NULL);
  }
}


x86 assembly (clang, -O0):
<exec_try_login_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11db <exec_try_login_user+0xab>
cmpl   $0x0,-0x1c(%rbp)
je     11a2 <exec_try_login_user+0x72>
mov    -0x10(%rbp),%rdi
call   1040 <switch_user@plt>
cmp    $0x0,%rax
jge    1187 <exec_try_login_user+0x57>
mov    -0x10(%rbp),%rsi
lea    0xe8a(%rip),%rdi
call   1030 <mydm_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <exec_try_login_user+0xc1>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1050 <execlp@plt>
mov    %eax,-0x4(%rbp)
jmp    11f1 <exec_try_login_user+0xc1>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r9
lea    0xe68(%rip),%rsi
lea    0xe64(%rip),%rdx
lea    0xe5f(%rip),%r8
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
mov    $0x0,%al
call   1050 <execlp@plt>
mov    %eax,-0x4(%rbp)
jmp    11f1 <exec_try_login_user+0xc1>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1050 <execlp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_try_login_user>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     1150 <exec_try_login_user+0x20>
mov    %rdi,%rbx
test   %edx,%edx
je     1166 <exec_try_login_user+0x36>
mov    %rbx,%rdi
call   1040 <switch_user@plt>
test   %rax,%rax
js     1195 <exec_try_login_user+0x65>
mov    %r14,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <execlp@plt>
movq   $0x0,(%rsp)
lea    0xea4(%rip),%rdi
lea    0xea0(%rip),%rdx
lea    0xe9b(%rip),%r8
mov    %rdi,%rsi
mov    %rbx,%rcx
mov    %r14,%r9
xor    %eax,%eax
call   1050 <execlp@plt>
jmp    11a9 <exec_try_login_user+0x79>
lea    0xe64(%rip),%rdi
mov    %rbx,%rsi
call   1030 <mydm_print@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Can not login user '%s'\0A\00"
@.str.1 = [3 x i8] c"su\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [3 x i8] c"-c\00"
define i32 @exec_try_login_user(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %28
10: ; preds = %3
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = load i8*, i8** %5
%15 = call i64 @switch_user(i8* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = call i32 @mydm_print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %4
br label %32
20: ; preds = %13
%21 = load i8*, i8** %6
%22 = load i8*, i8** %6
%23 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %21, i8* %22, i8* null)
store i32 %23, i32* %4
br label %32
24: ; preds = %10
%25 = load i8*, i8** %5
%26 = load i8*, i8** %6
%27 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %26, i8* null)
store i32 %27, i32* %4
br label %32
28: ; preds = %3
%29 = load i8*, i8** %6
%30 = load i8*, i8** %6
%31 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %29, i8* %30, i8* null)
store i32 %31, i32* %4
br label %32
32: ; preds = %28, %24, %20, %17
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [25 x i8] c"Can not login user '%s'\0A\00"
@.str.1 = [3 x i8] c"su\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [3 x i8] c"-c\00"
define i32 @exec_try_login_user(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = icmp eq i32 %2, 0
br i1 %6, label %14, label %7
7: ; preds = %5
%8 = tail call i64 @switch_user(i8* %0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @mydm_print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %18
12: ; preds = %7
%13 = tail call i32 (i8*, i8*, i8*, ...) @execlp(i8* %1, i8* %1, i8* null)
br label %18
14: ; preds = %5
%15 = tail call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* null)
br label %18
16: ; preds = %3
%17 = tail call i32 (i8*, i8*, i8*, ...) @execlp(i8* %1, i8* %1, i8* null)
br label %18
18: ; preds = %16, %14, %12, %10
%19 = phi i32 [ -1, %10 ], [ %13, %12 ], [ %15, %14 ], [ %17, %16 ]
ret i32 %19
}