#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 */
struct passwd {
  int /*<<< orphan*/ pw_name;
  scalar_t__ pw_uid;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ perror(char *);
scalar_t__ setuid(scalar_t__);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, int /*<<< orphan*/);
int change_uid(const struct passwd *info) {
  if (setuid(info->pw_uid)) {
    perror("setuid");
    syslog(LOG_ERR, "bad user ID `%d' for user `%s': %m\n", (int)info->pw_uid,
           info->pw_name);
    closelog();
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<change_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <setuid@plt>
cmp    $0x0,%rax
je     11a7 <change_uid+0x67>
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xe78(%rip),%rsi
call   1040 <syslog@plt>
mov    $0x0,%al
call   1030 <closelog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <change_uid+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_uid>:
push   %rbx
mov    %rdi,%rbx
mov    0x8(%rdi),%rdi
call   1060 <setuid@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1159 <change_uid+0x19>
pop    %rbx
ret
lea    0xea0(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%ecx
mov    0x8(%rbx),%edx
lea    0xe8d(%rip),%rsi
call   1040 <syslog@plt>
xor    %eax,%eax
call   1030 <closelog@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i32, i64 }
@.str = [7 x i8] c"setuid\00"
@LOG_ERR = global i32 0
@.str.1 = [36 x i8] c"bad user ID `%d' for user `%s': %m\0A\00"
define i32 @change_uid(%struct.passwd* %0) {
%2 = alloca i32
%3 = alloca %struct.passwd*
store %struct.passwd* %0, %struct.passwd** %3
%4 = load %struct.passwd*, %struct.passwd** %3
%5 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i32 0, i32 1
%6 = load i64, i64* %5
%7 = call i64 @setuid(i64 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @LOG_ERR
%12 = load %struct.passwd*, %struct.passwd** %3
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %12, i32 0, i32 1
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
%16 = load %struct.passwd*, %struct.passwd** %3
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @syslog(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %18)
%20 = call i32 (...) @closelog()
store i32 -1, i32* %2
br label %22
21: ; preds = %1
store i32 0, i32* %2
br label %22
22: ; preds = %21, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.passwd = type { i32, i64 }
@.str = [7 x i8] c"setuid\00"
@LOG_ERR = global i32 0
@.str.1 = [36 x i8] c"bad user ID `%d' for user `%s': %m\0A\00"
define i32 @change_uid(%struct.passwd* nocapture %0) {
%2 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 1
%3 = load i64, i64* %2
%4 = tail call i64 @setuid(i64 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @LOG_ERR
%9 = load i64, i64* %2
%10 = trunc i64 %9 to i32
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @syslog(i32 %8, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %12)
%14 = tail call i32 (...) @closelog()
br label %15
15: ; preds = %1, %6
%16 = phi i32 [ -1, %6 ], [ 0, %1 ]
ret i32 %16
}