#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ TIOCSTI;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ ioctl(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int rc = 0;
  char *cmd = "id -u -n\n";
  while (*cmd)
    rc += ioctl(0, TIOCSTI, cmd++);
  exit(rc ? EXIT_FAILURE : EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1181 <main+0x61>
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    %eax,%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
jmp    1141 <main+0x21>
cmpl   $0x0,-0x8(%rbp)
je     119c <main+0x7c>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <main+0x88>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2eb9(%rip),%r12
mov    (%r12),%esi
lea    0xec6(%rip),%r15
xor    %edi,%edi
mov    %r15d,%edx
call   1030 <ioctl@plt>
mov    %rax,%r14
mov    (%r12),%esi
lea    0x1(%r15),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    %rax,%rbx
add    %r14d,%ebx
mov    (%r12),%esi
lea    0x2(%r15),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    %rax,%r14
add    %ebx,%r14d
mov    (%r12),%esi
lea    0x3(%r15),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    %rax,%rbx
add    %r14d,%ebx
mov    (%r12),%esi
lea    0x4(%r15),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    %rax,%r14
add    %ebx,%r14d
mov    (%r12),%esi
lea    0x5(%r15),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    %rax,%rbx
add    %r14d,%ebx
mov    (%r12),%esi
lea    0x6(%r15),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    %rax,%r14
add    %ebx,%r14d
mov    (%r12),%esi
lea    0x7(%r15),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    %rax,%rbx
add    %r14d,%ebx
mov    (%r12),%esi
add    $0x8,%r15d
xor    %edi,%edi
mov    %r15d,%edx
call   1030 <ioctl@plt>
add    %ebx,%eax
jne    11fe <main+0xde>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"id -u -n\0A\00"
@TIOCSTI = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %3
br label %4
4: ; preds = %8, %0
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %4
%9 = load i32, i32* @TIOCSTI
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %3
%12 = ptrtoint i8* %10 to i32
%13 = call i64 @ioctl(i32 0, i32 %9, i32 %12)
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = add nsw i64 %15, %13
%17 = trunc i64 %16 to i32
store i32 %17, i32* %2
br label %4
18: ; preds = %4
%19 = load i32, i32* %2
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i32, i32* @EXIT_FAILURE
br label %25
23: ; preds = %18
%24 = load i32, i32* @EXIT_SUCCESS
br label %25
25: ; preds = %23, %21
%26 = phi i32 [ %22, %21 ], [ %24, %23 ]
%27 = call i32 @exit(i32 %26)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"id -u -n\0A\00"
@TIOCSTI = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @TIOCSTI
%2 = tail call i64 @ioctl(i32 0, i32 %1, i32 ptrtoint ([10 x i8]* @.str to i32))
%3 = trunc i64 %2 to i32
%4 = load i32, i32* @TIOCSTI
%5 = tail call i64 @ioctl(i32 0, i32 %4, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 1) to i32))
%6 = trunc i64 %5 to i32
%7 = add i32 %3, %6
%8 = load i32, i32* @TIOCSTI
%9 = tail call i64 @ioctl(i32 0, i32 %8, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 2) to i32))
%10 = trunc i64 %9 to i32
%11 = add i32 %7, %10
%12 = load i32, i32* @TIOCSTI
%13 = tail call i64 @ioctl(i32 0, i32 %12, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 3) to i32))
%14 = trunc i64 %13 to i32
%15 = add i32 %11, %14
%16 = load i32, i32* @TIOCSTI
%17 = tail call i64 @ioctl(i32 0, i32 %16, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 4) to i32))
%18 = trunc i64 %17 to i32
%19 = add i32 %15, %18
%20 = load i32, i32* @TIOCSTI
%21 = tail call i64 @ioctl(i32 0, i32 %20, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 5) to i32))
%22 = trunc i64 %21 to i32
%23 = add i32 %19, %22
%24 = load i32, i32* @TIOCSTI
%25 = tail call i64 @ioctl(i32 0, i32 %24, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 6) to i32))
%26 = trunc i64 %25 to i32
%27 = add i32 %23, %26
%28 = load i32, i32* @TIOCSTI
%29 = tail call i64 @ioctl(i32 0, i32 %28, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 7) to i32))
%30 = trunc i64 %29 to i32
%31 = add i32 %27, %30
%32 = load i32, i32* @TIOCSTI
%33 = tail call i64 @ioctl(i32 0, i32 %32, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 8) to i32))
%34 = trunc i64 %33 to i32
%35 = sub i32 0, %34
%36 = icmp eq i32 %31, %35
%37 = load i32, i32* @EXIT_FAILURE
%38 = load i32, i32* @EXIT_SUCCESS
%39 = select i1 %36, i32 %38, i32 %37
%40 = tail call i32 @exit(i32 %39)
unreachable
}