#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
char toupper(char);
int main(void) {
  FILE *fp;
  char line[150];
  int i;
  fp = popen("cat /etc/passwd", "r");
  while ((fgets(line, 150, fp)) != 0) {
    for (i = 0; line[i] != '\0'; i++)
      line[i] = toupper(line[i]);
    printf("%s", line);
  }
  pclose(fp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x10(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x96,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     121a <main+0xba>
movl   $0x0,-0xb4(%rbp)
movslq -0xb4(%rbp),%rax
movsbl -0xb0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     1202 <main+0xa2>
movslq -0xb4(%rbp),%rax
movsbl -0xb0(%rbp,%rax,1),%edi
ff
call   1030 <toupper@plt>
mov    %al,%cl
movslq -0xb4(%rbp),%rax
mov    %cl,-0xb0(%rbp,%rax,1)
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    11b2 <main+0x52>
lea    -0xb0(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
jmp    1189 <main+0x29>
mov    -0x10(%rbp),%rdi
call   1050 <pclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa0,%rsp
lea    0xe89(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x96,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11aa <main+0x4a>
mov    %r15,%rdi
call   1050 <pclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0x1(%rsp),%r12
lea    0xe5c(%rip),%r14
mov    %rsp,%r13
jmp    11e0 <main+0x80>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    $0x96,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     119b <main+0x3b>
mov    (%rsp),%al
test   %al,%al
je     11c0 <main+0x60>
mov    %r12,%rbx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11f0 <main+0x90>
jmp    11c0 <main+0x60>

LLVM IR (-O0):
@.str = [16 x i8] c"cat /etc/passwd\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [150 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @popen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
br label %6
6: ; preds = %31, %0
%7 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%8 = load i32*, i32** %2
%9 = call i64 @fgets(i8* %7, i32 150, i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %6
store i32 0, i32* %4
br label %12
12: ; preds = %28, %11
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %12
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = call signext i8 @toupper(i8 signext %23)
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 %26
store i8 %24, i8* %27
br label %28
28: ; preds = %19
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %12
31: ; preds = %12
%32 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %6
34: ; preds = %6
%35 = load i32*, i32** %2
%36 = call i32 @pclose(i32* %35)
%37 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [16 x i8] c"cat /etc/passwd\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [150 x i8]
%2 = getelementptr inbounds [150 x i8], [150 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i64 @fgets(i8* %2, i32 150, i32* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %0, %18
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %6, %9
%10 = phi i64 [ %14, %9 ], [ 0, %6 ]
%11 = phi i8 [ %16, %9 ], [ %7, %6 ]
%12 = phi i8* [ %15, %9 ], [ %2, %6 ]
%13 = call signext i8 @toupper(i8 signext %11)
store i8 %13, i8* %12
%14 = add nuw i64 %10, 1
%15 = getelementptr inbounds [150 x i8], [150 x i8]* %1, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %9
18: ; preds = %9, %6
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%20 = call i64 @fgets(i8* %2, i32 150, i32* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %6
22: ; preds = %18, %0
%23 = call i32 @pclose(i32* %3)
%24 = call i32 @exit(i32 0)
unreachable
}