#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char const *, int);
int main(int argc, const char *argv[], const char *envp[]) {
  const char *user = NULL;
  int i = 0;
  while (envp[i] != NULL) {
    if (strncmp("USER", envp[i], 4) == 0) {
      user = &envp[i][5];
      break;
    }
    ++i;
  }
  if (user == NULL) {
    fprintf(stderr, "Could not locale USER in environment variables.\n");
    return 1;
  }
  printf("Hello %s !\n", user);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11ba <main+0x8a>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe81(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ac <main+0x7c>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
jmp    11ba <main+0x8a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1159 <main+0x29>
cmpq   $0x0,-0x20(%rbp)
jne    11e6 <main+0xb6>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fd <main+0xcd>
mov    -0x20(%rbp),%rsi
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    (%rdx),%rsi
test   %rsi,%rsi
je     1170 <main+0x40>
mov    %rdx,%r15
xor    %ebx,%ebx
lea    0xeb7(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     118c <main+0x5c>
mov    0x8(%r15,%rbx,8),%rsi
add    $0x1,%rbx
test   %rsi,%rsi
jne    1150 <main+0x20>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11a4 <main+0x74>
mov    %ebx,%eax
mov    (%r15,%rax,8),%rsi
add    $0x5,%rsi
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"USER\00"
@stderr = global i32 0
@.str.1 = [49 x i8] c"Could not locale USER in environment variables.\0A\00"
@.str.2 = [12 x i8] c"Hello %s !\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i8* null, i8** %8
store i32 0, i32* %9
br label %10
10: ; preds = %32, %3
%11 = load i8**, i8*** %7
%12 = load i32, i32* %9
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %35
17: ; preds = %10
%18 = load i8**, i8*** %7
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %22, i32 4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %17
%26 = load i8**, i8*** %7
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8, i8* %30, i64 5
store i8* %31, i8** %8
br label %35
32: ; preds = %17
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %10
35: ; preds = %25, %10
%36 = load i8*, i8** %8
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %44
41: ; preds = %35
%42 = load i8*, i8** %8
%43 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %42)
store i32 0, i32* %4
br label %44
44: ; preds = %41, %38
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [5 x i8] c"USER\00"
@stderr = global i32 0
@.str.1 = [49 x i8] c"Could not locale USER in environment variables.\0A\00"
@.str.2 = [12 x i8] c"Hello %s !\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture %2) {
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %3, %11
%7 = phi i64 [ %12, %11 ], [ 0, %3 ]
%8 = phi i8* [ %14, %11 ], [ %4, %3 ]
%9 = tail call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %8, i32 4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %6
%12 = add nuw i64 %7, 1
%13 = getelementptr inbounds i8*, i8** %2, i64 %12
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %6
16: ; preds = %11, %3
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %25
19: ; preds = %6
%20 = and i64 %7, 4294967295
%21 = getelementptr inbounds i8*, i8** %2, i64 %20
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8, i8* %22, i64 5
%24 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %19, %16
%26 = phi i32 [ 1, %16 ], [ 0, %19 ]
ret i32 %26
}