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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeda(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     115d <main+0x4d>
mov    0x2eaa(%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>
jmp    112a <main+0x1a>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ecd(%rip),%r14
mov    (%r14),%esi
lea    0xedb(%rip),%rbx
xor    %edi,%edi
mov    %ebx,%edx
call   1030 <ioctl@plt>
mov    (%r14),%esi
lea    0x1(%rbx),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    (%r14),%esi
lea    0x2(%rbx),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    (%r14),%esi
lea    0x3(%rbx),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    (%r14),%esi
lea    0x4(%rbx),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    (%r14),%esi
lea    0x5(%rbx),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    (%r14),%esi
lea    0x6(%rbx),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    (%r14),%esi
lea    0x7(%rbx),%edx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    (%r14),%esi
add    $0x8,%ebx
xor    %edi,%edi
mov    %ebx,%edx
call   1030 <ioctl@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"id -u -n\0A\00"
@TIOCSTI = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
br label %3
3: ; preds = %7, %0
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = icmp ne i8 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = load i32, i32* @TIOCSTI
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %2
%11 = ptrtoint i8* %9 to i32
%12 = call i32 @ioctl(i32 0, i32 %8, i32 %11)
br label %3
13: ; preds = %3
%14 = load i32, i32* %1
ret i32 %14
}

LLVM IR (-O2):
@.str = [10 x i8] c"id -u -n\0A\00"
@TIOCSTI = global i32 0
define i32 @main() {
%1 = load i32, i32* @TIOCSTI
%2 = tail call i32 @ioctl(i32 0, i32 %1, i32 ptrtoint ([10 x i8]* @.str to i32))
%3 = load i32, i32* @TIOCSTI
%4 = tail call i32 @ioctl(i32 0, i32 %3, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 1) to i32))
%5 = load i32, i32* @TIOCSTI
%6 = tail call i32 @ioctl(i32 0, i32 %5, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 2) to i32))
%7 = load i32, i32* @TIOCSTI
%8 = tail call i32 @ioctl(i32 0, i32 %7, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 3) to i32))
%9 = load i32, i32* @TIOCSTI
%10 = tail call i32 @ioctl(i32 0, i32 %9, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 4) to i32))
%11 = load i32, i32* @TIOCSTI
%12 = tail call i32 @ioctl(i32 0, i32 %11, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 5) to i32))
%13 = load i32, i32* @TIOCSTI
%14 = tail call i32 @ioctl(i32 0, i32 %13, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 6) to i32))
%15 = load i32, i32* @TIOCSTI
%16 = tail call i32 @ioctl(i32 0, i32 %15, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 7) to i32))
%17 = load i32, i32* @TIOCSTI
%18 = tail call i32 @ioctl(i32 0, i32 %17, i32 ptrtoint (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 8) to i32))
ret i32 0
}