#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 scalar_t__ uid_t;
struct passwd {
  int pw_gid;
  int /*<<< orphan*/ *pw_passwd;
  int /*<<< orphan*/ *pw_gecos;
  scalar_t__ pw_uid;
  int /*<<< orphan*/ *pw_shell;
  int /*<<< orphan*/ *pw_dir;
  int /*<<< orphan*/ *pw_name;
};

/* Variables and functions */
void *field_from_line(char *, int);
char *find_line(char const *, char *, int);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int int_field_from_line(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int strlen(int /*<<< orphan*/ *);
struct passwd *internal_getpwuid(const char *filename, uid_t uid) {
  static struct passwd retpw;
  char find[10], *line;
  snprintf(find, 10, "%d", (int)uid);
  line = find_line(filename, find, 2);
  if (line) {
    retpw.pw_name = field_from_line(line, 0);
    retpw.pw_gid = int_field_from_line(line, 3);
    retpw.pw_dir = field_from_line(line, 5);
    retpw.pw_shell = field_from_line(line, 6);
    if (retpw.pw_name == NULL || retpw.pw_gid == -1 || retpw.pw_shell == NULL ||
        retpw.pw_dir == NULL || strlen(retpw.pw_name) < 1 ||
        strlen(retpw.pw_dir) < 1 || strlen(retpw.pw_shell) < 1) {
      if (retpw.pw_name)
        free(retpw.pw_name);
      if (retpw.pw_dir)
        free(retpw.pw_dir);
      if (retpw.pw_shell)
        free(retpw.pw_shell);
      return NULL;
    }
    retpw.pw_uid = uid;
    retpw.pw_gecos = NULL;
    retpw.pw_passwd = NULL;
    return &retpw;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<internal_getpwuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    $0xa,%esi
lea    0xe7a(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
call   1080 <find_line@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12fe <internal_getpwuid+0x19e>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1070 <field_from_line@plt>
mov    %rax,0x2eca(%rip)
mov    -0x30(%rbp),%rdi
mov    $0x3,%esi
call   1060 <int_field_from_line@plt>
mov    %eax,0x2e86(%rip)
mov    -0x30(%rbp),%rdi
mov    $0x5,%esi
call   1070 <field_from_line@plt>
mov    %rax,0x2e99(%rip)
mov    -0x30(%rbp),%rdi
mov    $0x6,%esi
call   1070 <field_from_line@plt>
mov    %rax,0x2e7c(%rip)
cmpq   $0x0,0x2e84(%rip)
je     1272 <internal_getpwuid+0x112>
cmpl   $0xffffffff,0x2e47(%rip)
je     1272 <internal_getpwuid+0x112>
cmpq   $0x0,0x2e59(%rip)
je     1272 <internal_getpwuid+0x112>
cmpq   $0x0,0x2e53(%rip)
je     1272 <internal_getpwuid+0x112>
mov    0x2e4e(%rip),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jl     1272 <internal_getpwuid+0x112>
mov    0x2e31(%rip),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jl     1272 <internal_getpwuid+0x112>
mov    0x2e14(%rip),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jge    12cd <internal_getpwuid+0x16d>
cmpq   $0x0,0x2e0e(%rip)
je     128c <internal_getpwuid+0x12c>
mov    0x2e01(%rip),%rdi
call   1030 <free@plt>
cmpq   $0x0,0x2dec(%rip)
je     12a6 <internal_getpwuid+0x146>
mov    0x2ddf(%rip),%rdi
call   1030 <free@plt>
cmpq   $0x0,0x2dca(%rip)
je     12c0 <internal_getpwuid+0x160>
mov    0x2dbd(%rip),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1306 <internal_getpwuid+0x1a6>
mov    -0x18(%rbp),%rax
mov    %rax,0x2d98(%rip)
movq   $0x0,0x2d85(%rip)
movq   $0x0,0x2d72(%rip)
lea    0x2d63(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1306 <internal_getpwuid+0x1a6>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<internal_getpwuid>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe8a(%rip),%rdx
lea    0x6(%rsp),%r15
mov    %r15,%rdi
mov    $0xa,%esi
mov    %r14d,%ecx
call   1050 <snprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1080 <find_line@plt>
test   %rax,%rax
je     128d <internal_getpwuid+0x12d>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1070 <field_from_line@plt>
mov    %rax,0x2ed0(%rip)
mov    %rbx,%rdi
mov    $0x3,%esi
call   1060 <int_field_from_line@plt>
mov    %eax,0x2e8d(%rip)
mov    %rbx,%rdi
mov    $0x5,%esi
call   1070 <field_from_line@plt>
mov    %rax,0x2ea1(%rip)
mov    %rbx,%rdi
mov    $0x6,%esi
call   1070 <field_from_line@plt>
mov    %rax,0x2e85(%rip)
mov    0x2e8e(%rip),%rdi
test   %rdi,%rdi
je     125a <internal_getpwuid+0xfa>
cmpl   $0xffffffff,0x2e52(%rip)
je     125a <internal_getpwuid+0xfa>
test   %rax,%rax
je     125a <internal_getpwuid+0xfa>
cmpq   $0x0,0x2e6b(%rip)
je     125a <internal_getpwuid+0xfa>
call   1040 <strlen@plt>
test   %eax,%eax
jle    125a <internal_getpwuid+0xfa>
mov    0x2e59(%rip),%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    125a <internal_getpwuid+0xfa>
mov    0x2e41(%rip),%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    125a <internal_getpwuid+0xfa>
mov    %r14,0x2e29(%rip)
lea    0x2e0a(%rip),%rax
xorps  %xmm0,%xmm0
movups %xmm0,0x2e08(%rip)
jmp    128f <internal_getpwuid+0x12f>
mov    0x2e27(%rip),%rdi
test   %rdi,%rdi
je     126b <internal_getpwuid+0x10b>
call   1030 <free@plt>
mov    0x2e0e(%rip),%rdi
test   %rdi,%rdi
je     127c <internal_getpwuid+0x11c>
call   1030 <free@plt>
mov    0x2df5(%rip),%rdi
test   %rdi,%rdi
je     128d <internal_getpwuid+0x12d>
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.passwd = type { i32, i32*, i32*, i64, i32*, i32*, i32* }
@internal_getpwuid.retpw = internal global %struct.passwd zeroinitializer
@.str = [3 x i8] c"%d\00"
define %struct.passwd* @internal_getpwuid(i8* %0, i64 %1) {
%3 = alloca %struct.passwd*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [10 x i8]
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%9 = load i64, i64* %5
%10 = trunc i64 %9 to i32
%11 = call i32 @snprintf(i8* %8, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i8*, i8** %4
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%14 = call i8* @find_line(i8* %12, i8* %13, i32 2)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %73
17: ; preds = %2
%18 = load i8*, i8** %7
%19 = call i8* @field_from_line(i8* %18, i32 0)
%20 = bitcast i8* %19 to i32*
store i32* %20, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 6)
%21 = load i8*, i8** %7
%22 = call i32 @int_field_from_line(i8* %21, i32 3)
store i32 %22, i32* getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 0)
%23 = load i8*, i8** %7
%24 = call i8* @field_from_line(i8* %23, i32 5)
%25 = bitcast i8* %24 to i32*
store i32* %25, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 5)
%26 = load i8*, i8** %7
%27 = call i8* @field_from_line(i8* %26, i32 6)
%28 = bitcast i8* %27 to i32*
store i32* %28, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 4)
%29 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 6)
%30 = icmp eq i32* %29, null
br i1 %30, label %52, label %31
31: ; preds = %17
%32 = load i32, i32* getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 0)
%33 = icmp eq i32 %32, -1
br i1 %33, label %52, label %34
34: ; preds = %31
%35 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 4)
%36 = icmp eq i32* %35, null
br i1 %36, label %52, label %37
37: ; preds = %34
%38 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 5)
%39 = icmp eq i32* %38, null
br i1 %39, label %52, label %40
40: ; preds = %37
%41 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 6)
%42 = call i32 @strlen(i32* %41)
%43 = icmp slt i32 %42, 1
br i1 %43, label %52, label %44
44: ; preds = %40
%45 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 5)
%46 = call i32 @strlen(i32* %45)
%47 = icmp slt i32 %46, 1
br i1 %47, label %52, label %48
48: ; preds = %44
%49 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 4)
%50 = call i32 @strlen(i32* %49)
%51 = icmp slt i32 %50, 1
br i1 %51, label %52, label %71
52: ; preds = %48, %44, %40, %37, %34, %31, %17
%53 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 6)
%54 = icmp ne i32* %53, null
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 6)
%57 = call i32 @free(i32* %56)
br label %58
58: ; preds = %55, %52
%59 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 5)
%60 = icmp ne i32* %59, null
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 5)
%63 = call i32 @free(i32* %62)
br label %64
64: ; preds = %61, %58
%65 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 4)
%66 = icmp ne i32* %65, null
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 4)
%69 = call i32 @free(i32* %68)
br label %70
70: ; preds = %67, %64
store %struct.passwd* null, %struct.passwd** %3
br label %74
71: ; preds = %48
%72 = load i64, i64* %5
store i64 %72, i64* getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 3)
store i32* null, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 2)
store i32* null, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i32 0, i32 1)
store %struct.passwd* @internal_getpwuid.retpw, %struct.passwd** %3
br label %74
73: ; preds = %2
store %struct.passwd* null, %struct.passwd** %3
br label %74
74: ; preds = %73, %71, %70
%75 = load %struct.passwd*, %struct.passwd** %3
ret %struct.passwd* %75
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32*, i32*, i64, i32*, i32*, i32* }
@internal_getpwuid.retpw = internal global %struct.passwd zeroinitializer
@.str = [3 x i8] c"%d\00"
define %struct.passwd* @internal_getpwuid(i8* %0, i64 %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = trunc i64 %1 to i32
%6 = call i32 @snprintf(i8* %4, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i8* @find_line(i8* %0, i8* %4, i32 2)
%8 = icmp eq i8* %7, null
br i1 %8, label %51, label %9
9: ; preds = %2
%10 = call i8* @field_from_line(i8* %7, i32 0)
store i8* %10, i8** bitcast (i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 6) to i8**)
%11 = call i32 @int_field_from_line(i8* %7, i32 3)
store i32 %11, i32* getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 0)
%12 = call i8* @field_from_line(i8* %7, i32 5)
store i8* %12, i8** bitcast (i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 5) to i8**)
%13 = call i8* @field_from_line(i8* %7, i32 6)
store i8* %13, i8** bitcast (i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 4) to i8**)
%14 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 6)
%15 = icmp eq i32* %14, null
%16 = load i32, i32* getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 0)
%17 = icmp eq i32 %16, -1
%18 = select i1 %15, i1 true, i1 %17
%19 = icmp eq i8* %13, null
%20 = select i1 %18, i1 true, i1 %19
%21 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 5)
%22 = icmp eq i32* %21, null
%23 = select i1 %20, i1 true, i1 %22
br i1 %23, label %35, label %24
24: ; preds = %9
%25 = call i32 @strlen(i32* %14)
%26 = icmp slt i32 %25, 1
br i1 %26, label %35, label %27
27: ; preds = %24
%28 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 5)
%29 = call i32 @strlen(i32* %28)
%30 = icmp slt i32 %29, 1
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 4)
%33 = call i32 @strlen(i32* %32)
%34 = icmp slt i32 %33, 1
br i1 %34, label %35, label %50
35: ; preds = %31, %27, %24, %9
%36 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 6)
%37 = icmp eq i32* %36, null
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @free(i32* %36)
br label %40
40: ; preds = %38, %35
%41 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 5)
%42 = icmp eq i32* %41, null
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = call i32 @free(i32* %41)
br label %45
45: ; preds = %43, %40
%46 = load i32*, i32** getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 4)
%47 = icmp eq i32* %46, null
br i1 %47, label %51, label %48
48: ; preds = %45
%49 = call i32 @free(i32* %46)
br label %51
50: ; preds = %31
store i64 %1, i64* getelementptr inbounds (%struct.passwd, %struct.passwd* @internal_getpwuid.retpw, i64 0, i32 3)
br label %51
51: ; preds = %2, %45, %48, %50
%52 = phi %struct.passwd* [ @internal_getpwuid.retpw, %50 ], [ null, %48 ], [ null, %45 ], [ null, %2 ]
ret %struct.passwd* %52
}